哪种方法可以从JavaScript中的返回对象引用私有方法?我离开你一些示例代码:如何从javascript中的返回对象引用私有方法?
var HelloWorld = (function(){
var hello = function(){
console.log("hello")
},
return{
addToList: function(){
//how can i reference hello from here dynamically like:
//this["hello"] or this["hell" + "o"]
}
}
})()
你有没有尝试过?发生了什么? ''['hello']();'对我来说似乎很好...... – 11684
顺便说一句,你有一个语法错误,你应该在'hello'函数声明后面加一个分号,而不是逗号。 – 11684
不知道你是否也遇到过这个问题,但是在返回之前/之后的hello函数应该是';'。 – ericponto