新的不返回构造函数function.prototype对象

时间:2013-01-27 02:16:01

标签: javascript google-chrome

我对构造函数的理解是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();

请参阅调试程序截图。

0 个答案:

没有答案
相关问题