<html>
<body>
<script>
function Car(c,d){
this.color=c;
this.speed=d;
}
var car1=new Car("red",100);
var car2=new Car("blue",200);
document.write(car1.color+","+car1.speed+"<br>"); // red,100
document.write(car2.color+","+car2.speed); // blue,200
</script>
</body>
</html>
<html>
<body>
<script>
function A(){
this.a=100;
this.b=function(){ return 200; }
this.c=f1;
}
function f1(){
return 300;
}
var o=new A();
document.write(o.a); // 100
document.write(o.b()); // 200
document.write(o.c()); // 300
</script>
</body>
</html>
'개발하자 > 자바스크립트' 카테고리의 다른 글
원하는 객체의 값 변경(강아지 이름 변경 예제) (0) | 2015.02.14 |
---|---|
원하는 객체의 값 변경(자동차 색상 예제) (0) | 2015.02.14 |
css를 외부파일로 만들어서 사용하기 (0) | 2015.02.14 |
js파일에 함수 모아두고 호출해서 사용하기 (0) | 2015.02.14 |
내용 복사/지우기 함수이용 (0) | 2015.02.14 |