개발하자/자바스크립트
원하는 객체의 값 변경(자동차 색상 예제)
i구야
2015. 2. 14. 11:45
<html>
<body>
<script>
function Car(c){
this.color=c;
this.changeColor=function(c2){this.color=c2};
}
var car1=new Car("red");
var car2=new Car("blue");
document.write(car1.color+"<br>"); // red
document.write(car2.color+"<br>"); // blue
car1.changeColor("pink");
document.write(car1.color); // pink
document.write(car2.color); // blue
</script>
</body>
</html>