개발하자/자바스크립트

Car.prototype.getSpeed

i구야 2015. 2. 24. 15:49

<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>