<html>
<body>
<script>
function Car(a,b){
this.color=a;
this.speed=b;
this.getColor=function(){
return this.color;
}
}
var car1=new Car("red",100);
document.write(car1.getColor()); // red
Car.prototype.getSpeed=function(){ return this.speed; }
document.write(car1.getSpeed()+"<br>");
var car2=new Car("blue",200);
document.write(car2.getColor()); // blue
document.write(car2.getSpeed());
</script>
</body>
</html>
'개발하자 > 자바스크립트' 카테고리의 다른 글
event객체 visibility-visible,hidden (0) | 2015.02.24 |
---|---|
prototype 으로 메서드 생성해서 공용으로 사용하기 (0) | 2015.02.24 |
prototype (0) | 2015.02.24 |
StringBuffer (0) | 2015.02.24 |
sort (0) | 2015.02.24 |