{"id":230,"date":"2007-08-16T22:47:45","date_gmt":"2007-08-17T03:47:45","guid":{"rendered":"http:\/\/www.phpied.com\/javascript-calling-the-unnamed\/"},"modified":"2007-08-17T16:16:35","modified_gmt":"2007-08-17T21:16:35","slug":"javascript-calling-the-unnamed","status":"publish","type":"post","link":"https:\/\/www.phpied.com\/javascript-calling-the-unnamed\/","title":{"rendered":"JavaScript: Calling the unnamed"},"content":{"rendered":"<p>How does this look like?<\/p>\n<pre>o[\"\"]()<\/pre>\n<p>A bit like a syntax error, eh? Or <a href=\"http:\/\/en.wikipedia.org\/wiki\/Emoticon#Common_examples\">an emoticon<\/a> of some sort. Well, it's valid JavaScript code.<\/p>\n<p>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.<\/p>\n<p>So type this in your Firebug console:<\/p>\n<pre>\r\nvar o = {\r\n  \"\": function(){\r\n        console.log('here')\r\n      }\r\n}\r\n<\/pre>\n<p>then call the unnamed like o[\"\"]()<\/p>\n<p>It works!<\/p>\n<p>Reminds me of the <a href=\"http:\/\/en.wikipedia.org\/wiki\/A_Wizard_of_Earthsea\">Wizard of Earthsea<\/a> a little bit where you had to know the true names of things in order to do the wizardry.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How does this look like? o[&#8220;&#8221;]() A bit like a syntax error, eh? Or an emoticon of some sort. Well, it&#8217;s valid JavaScript code. JavaScript objects can have an empty string as a name for a property\/method. So if you create an unnamed method called &#8220;&#8221;, you can&#8217;t call it using the dot notation, but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts\/230"}],"collection":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":0,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpied.com\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}