我对构造函数的理解是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();
请参阅调试程序截图。