Javascript inheritance: calling Object.create when setting a prototype

后端 未结 2 1435
醉酒成梦
醉酒成梦 2020-12-06 18:34

I\'m learning some aspects of Object-oriented Javascript. I came across this snippet

var Person = function(firstName, lastName)
{
  this.lastName = lastName         


        
2条回答
  •  长情又很酷
    2020-12-06 18:36

    My guess is that the intent is to create a new object rather than just a reference from Person.

    //create a new object with its prototype assigned to Person.prototype
    Employee.prototype = Object.create(Person.prototype);
    

提交回复
热议问题