0

我对构造函数的理解,就是new 返回构造函数的原型对象。但是,在下面的代码中,new Customer()似乎返回了 Customer 对象,我原以为它会返回 Customer.prototype,即 Person。我的理解错了吗?

function Person(name){
this.name = name;
}

function Customer(){
}
//* inherit from  Person This creates an object from Person.Prototype
Customer.prototype = new Person("James");

var newCustomer = new Customer();//*this should return Customer. prototype object-             
                                   which is  Person*// 

newCustomer.sayHello = function() { 
console.log( "newCustomer  " + this.name + "says Hello" ) ;         
 }
 newCustomer.sayHello();

请参阅调试器屏幕截图。

4

0 回答 0