본문 바로가기

개발하자/자바스크립트

객체생성하는방법1

<html>
 <body>
 <script>
 function Dog(n,b,a){
  this.name=n;
  this.getBreed=function(){
   return b;
  }
  this.getAge=function(){
   return a;
  }
 }

 var dog1=new Dog("똘망이","씨추",10);
 document.write(dog1.name);
 document.write(dog1.getBreed());
 document.write(dog1.getAge());


 var dog2=new Dog("뚱돌이","페키니즈",5);
 document.write(dog2.name);
 document.write(dog2.getBreed());
 document.write(dog2.getAge());


 </script>
 </body>
</html>