How does this look like?
看起来如何?
o[""]()
A bit like a syntax error, eh? Or an emoticon of some sort. Well, it's valid JavaScript code.
有点像语法错误,是吗? 或某种表情符号。 嗯,这是有效JavaScript代码。
JavaScript objects can have an empty string as a name for a property/method. So if you create an unnamed method called "", you can't call it using the dot notation, but you can, using the brackets.
JavaScript对象可以使用一个空字符串作为属性/方法的名称。 因此,如果创建一个名为“”的未命名方法,则不能使用点符号来调用它,但是可以使用方括号来调用它。
So type this in your Firebug console:
因此,在您的Firebug控制台中输入以下内容:
var o = {
"": function(){
console.log('here')
}
}
then call the unnamed like o[""]()
然后像o [“”]()一样调用未命名的
It works!
有用!
Reminds me of the Wizard of Earthsea a little bit where you had to know the true names of things in order to do the wizardry.
让我想起了地球海的巫师,在这里您必须知道事物的真实名称才能进行巫术。
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
翻译自: https://www.phpied.com/javascript>javascript-calling-the-unnamed/