Looks like
Object.getPrototypeOf;
Is the answer.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf http://ejohn.org/blog/objectgetprototypeof/
سؤال
I need to access properties and methods one level up in the prototype chain, when using prototypal inheritance.
Is this an acceptable technique?
function Cheese() {
this.weight = 100;
this.unit = 'g';
this.that = this; // not sure about this... does it create a circular reference?
}
Cheese.prototype.setWeight = function(myWeight) {
this.weight = myWeight;
}
var cheese = new Cheese();
var myCheddar = Object.create(cheese); // http://javascript.crockford.com/prototypal.html
myCheddar.setWeight(500);
console.log(myCheddar.weight + myCheddar.unit); //-> 100kg
console.log(myCheddar.that.weight + myCheddar.unit); //-> 500g
لا يوجد حل صحيح
نصائح أخرى
Looks like
Object.getPrototypeOf;
Is the answer.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf http://ejohn.org/blog/objectgetprototypeof/