3. 조합 승계

5891 단어
<body>

  <script>
  function Person(name,age){
    this.name = name
    this.age = age
  }

Person.prototype.setName = function(name){
  this.name = name
}

  function Student(name,age,price){
    Person.call(this,name,age) // :this.Person(name,age)
    //!!!!call 
    //this.name = name
    //this.age = age
    this.price = price
  }

Student.prototype = new Person()// 
Student.prototype,constructor = Student
Student.prototype.setPrice = function(price){
  this.price = price
}

  var s = new Student('Tom',20,4000)
  s.setName('Bob')
  s.setPrice(15000)
  console.log(s.name,s.age,s.price) //   // 

  script>
  
body>

좋은 웹페이지 즐겨찾기