3 回答

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
JavaScript本身不提供此功能。而且我懷疑您是否可以創(chuàng)建此類功能。例如:
var Bobby = {name: "Bobby"};
var Dad = {name: "Dad", children: [ Bobby ]};
var Mom = {name: "Mom", children: [ Bobby ]};
鮑比屬于誰(shuí)?

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊
在這種情況下,您可以life用來(lái)引用父對(duì)象?;蛘?,您可以life在用戶對(duì)象中存儲(chǔ)對(duì)的引用。parent語(yǔ)言中沒(méi)有固定的可用內(nèi)容,因?yàn)橛脩糁皇菍?duì)對(duì)象的引用,并且可能還有其他引用...
var death = { residents : life.users };
life.users.smallFurryCreaturesFromAlphaCentauri = { exist : function() {} };
// death.residents.smallFurryCreaturesFromAlphaCentauri now exists
// - because life.users references the same object as death.residents!
您可能會(huì)發(fā)現(xiàn)使用類似以下內(nèi)容可能會(huì)有所幫助:
function addChild(ob, childName, childOb)
{
ob[childName] = childOb;
childOb.parent = ob;
}
var life= {
mameAndDestroy : function(group){ },
kiss : function(group){ }
};
addChild(life, 'users', {
guys : function(){ this.parent.mameAndDestroy(this.girls); },
girls : function(){ this.parent.kiss(this.boys); },
});
// life.users.parent now exists and points to life
添加回答
舉報(bào)