嗨,大家好我有一個關於OBJ問題在javascript 我怎麼能訪問父類的屬性訪問從子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」是subObj,我怎麼能訪問parentclass.name? 任何人都可以幫忙?
在'function(){...}'表達式之前跳過'new'。它使用'function'作爲構造函數立即創建一個實例。 –
@JonathanLonowski sry當我寫這個問題時,錯字.. thx反正^^ –