JavaScript:调用未命名

news/2024/7/19 15:21:55 标签: javascript, php, python, java, js

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/


http://www.niftyadmin.cn/n/1306524.html

相关文章

JSP标签c:forEach报错(一)

1、jsp标签c:forEach报错,具体错误如下: 三月 31, 2014 9:31:14 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [jsp] in context with path [/HighCharts] threw exception [Unable to compile cla…

php 数据库还原操作,SQL Server还原数据库操作详细步骤

欢迎进入Windows社区论坛,与300万技术人员互动交流 >>进入 --解决还原数据库目录不对的详细步骤: 1.企业管理器中的方法: --右键"数据库" --所有任务 --还原数据库 --"还原为数据库库"中输入还原后的数据库名 --还…

用于PHP4的file_put_contents()

Simplified, but still... 简化&#xff0c;但仍然... <?phpif (!function_exists(file_put_contents)) {function file_put_contents($filename, $data) {$f fopen($filename, w);if (!$f) {return false;} else {$bytes fwrite($f, $data);fclose($f);return $bytes;}}…

JSP标签c:forEach报错(二)

1、今天&#xff0c;我在用c标签写一些样例&#xff0c;结果出现一些错误&#xff0c;写下作为记录 具体错误如下&#xff1a; 三月 31, 2014 9:46:28 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [jsp] in context with …

求java平均值的算法,比较安全的两整数平均值算法实现

求两个整数的平均值这个问题相信大家都想过&#xff0c;大家肯定会很快的写出以下的 public static int mean(int a, int b){return (a b) / 2;}或者public static int mean(int a, int b){return (a b) >> 1;}或者public static int mean(int a, int b){return (a b)…

世界程序员的发展史_“有史以来最好的程序员”

世界程序员的发展史Go ahead, do a Yahoo search for "best programmer ever". Not surprisingly #1 result is the blog of yours truly &#x1f642; 继续&#xff0c;进行Yahoo搜索“有史以来最好的程序员”。 毫不奇怪&#xff0c;您的博客确实是&#xff03;1结…

JSP标签c:forEach实例

JSP标签c:forEach实例 1、实例源码 <% page language"java" import"java.util.*" pageEncoding"UTF-8"%> <%taglib prefix"c" uri"http://java.sun.com/jstl/core_rt"%> <!DOCTYPE html PUBLIC "-//W3C…

oracle 数据库连接协议,Oracle 配置连接远程数据库的教程

客户机为了和服务器连接&#xff0c;必须先和服务器上的监听进程联络。ORACLE通过tnsnames.ora文件中的连接描述符来说明连接信息。一般tnsnames.ora 是建立在客户机上的。如果是客户机/服务器结构&#xff0c;整个网络上只有一台机器安装了ORACLE数据库服务器&#xff0c;那么…