使用 Object.create(someObj.prototype) 创建的对象的构造函数为 someObj,那么当我尝试访问 someObj 的属性时,怎么会出现未定义?
function foo(){
this.name1 = "Name";
this.otherName1 = "someOtherName";
}
var fooObj = new foo();
console.log(fooObj.name1); // Name
var barObj = Object.create(foo.prototype);
console.log(barObj.constructor);
//Outouts:
// function foo(){
// this.name1 = "Name";
// this.otherName1 = "someOtherName" ;
// }
//Then why not able to access this?
console.log(barObj.name1); Outputs; // undefined