为了动态代码,我需要ObjectOne.featureChanged的addEventListener回调函数作为ObjectTwo中特定于功能的函数。将EventListener中的回调函数设置为其他对象中的函数可以正常工作。当我有一个字符串,该字符串具有需要连接的功能名称时#39;到回调函数'继承路径。'我的搜索范围很广,但窗口和评估对我来说都不适合。预先连接整个路径也不起作用。
window.onload = function() {
ObjectOneInstance.startup();
}
ObjectOne = {
startup: function() {
this.featureChanged.currFeature = null;
document.getElementById("FeatureOne").addEventListener("click", ObjectTwo.FeatureOne, false);
},
featureChanged: function(newFeature) {
var self = this.featureChanged;
if (self.currFeature == null) {
self.currFeature = newFeature;
//*****Below is where the problem resides*****//
document.getElementById(self.currFeature).removeEventListener("click", ObjectTwo.window[self.currFeature], false);
} else {
document.getElementById(self.currFeature).addEventListener("click", ObjectTwo.window[self.currFeature], false);
document.getElementById(newFeature).removeEventListener("click", ObjectTwo.window[newFeature], false);
self.currFeature = newFeature;
}
}
}
ObjectTwo = {
FeatureOne: function() {
FeaturesSupportModuleInstance.featureChanged("financial");
//feature functionality Here
}
}
var ObjectOneInstance = Object.create(ObjectOne);
var ObjectTwoInstance = Object.create(ObjectTwo);