我正在尝试这样做:
var myVar = {
"phantom-ee": {
doWork: function() {
},
doOtherWork: function() {}
},
"sameAsPhantom": myVar["phantom-ee"]
}
然而,我得到一个myVar是未定义的。我也尝试过:
var myVar = {
"phantom-ee": {
doWork: function() {
},
doOtherWork: function() {}
},
"sameAsPhantom": this["phantom-ee"]
}
此代码不会在定义上引发错误,但会在执行期间...
我如何将sameAsPhantom引用与phantom-ee相同的对象?
答案 0 :(得分:1)
var myVar = {
'phantom-ee': {
doWork: function() {
},
doOtherWork: function() {}
}
};
myVar.sameAsPhantom = myVar['phantom-ee'];
JSFiddle演示:https://jsfiddle.net/yteuqfg1/