如何调用名称中包含句点的 javascript 中的函数?
How can I call a function in javascript that contains a period in it's name?
如果我有以下对象:
var helloWorldFunctions = {
'hello.world': function () { return 'hello world'},
'helloWorld' : function () { return 'hello world'}
}
我可以通过以下方式调用对象中的第二个 'helloWorld' 函数:
helloWorldFunctions.helloWorld()
如何调用第一个 'hello.world' 函数?自然地,执行以下操作会出现类型错误:
helloWorldFunctions.hello.world()
正如 Rajaprabhu 在评论中所建议的那样,您可以使用:
helloWorldFunctions['hello.world']()
如果我有以下对象:
var helloWorldFunctions = {
'hello.world': function () { return 'hello world'},
'helloWorld' : function () { return 'hello world'}
}
我可以通过以下方式调用对象中的第二个 'helloWorld' 函数:
helloWorldFunctions.helloWorld()
如何调用第一个 'hello.world' 函数?自然地,执行以下操作会出现类型错误:
helloWorldFunctions.hello.world()
正如 Rajaprabhu 在评论中所建议的那样,您可以使用:
helloWorldFunctions['hello.world']()