JavaScript中原型对象和继承的问题
function Test1(){
Test1.prototype.name="zhang";
}
function Test2(){
}
Test2.prototype=Test1.prototype;
var obj2=new Test2();
console.log(obj2.name);
console.log(obj2.constructor);
将Test2的对象原型指向Test1的对象原型,然后创建Test2的对象实例,为什么能访问constructor,但不能访问name?而下面的又能访问
function Test1(){
}
function Test2(){
}
Test1.prototype={
name:"zhang"
};
Test2.prototype=Test1.prototype;
var obj2=new Test2();
console.log(obj2.name);
console.log(obj2.constructor);