我有一个关于 Javascript 对象的问题。如何访问父类的属性?
function randomObj() // for example button obj
{
this.text = "this is obj";
}
function parentClass()
{
this.name = "parent";
this.subObj;
}
parentClass.prototype.generate = function()
{
this.subObj = new randomObj();
this.subObj.changeParentClassName = function() // button obj wants to change name
{
this.name = "not parent";
}
}
var sampleObj = new parentClass();
sampleObj.generate();
sampleObj.subObj.changeParentClassName (); // does not works
'changeParentClassName'中的'this'似乎是subObj,我怎样才能访问parentclass.name?