Callable Objects
We learned in 7.11 that there are "array-like" objects that are not true arrays but can be treated like arrays for most purposes. A similar situation exists for functions. A callable object is any object that can be invoked in a function invocation expression. All function are callable, but not all callable objects are functions.
Callable objects that are not functions are encounted in two situations in today's JavaScript implementations. First, the IE web browser (version 8 and before) implements client-side methods such as Window.alert() and Document.getElementById() using callable host objects rather than native Function objects. The method work the same in IE as they do in other browsers, but they are not actually Function objects. IE9 switches to using true functions, so this kind of callable object will gradually become less common.
The other common form of callable objects are RegExp object directly as a shortcut for invoking its exec() method. This is a completely nonstandard feature of JavaScript that was introduced by Netscope and copied by other vendors for compatibility. Do not write code that relies on the callability of RegExp objects: this feature is likely to be deprecated and removed in the futrue. The typeof operator is not interoperable for callable RegExps. In some browsers it returns "function" and in others it returns "object".
If you want to determine whether an object is a true function object (and has function methods) you can test its class attribute using the technique shown in Example 6-4:
function isFunction(x) {
return Object.prototype.toString.call(x) === "[object Function]";
}
Note that this isFunction() function is quite similar to the isArray() function shown in 7.10.
Callable Objects的更多相关文章
- [c++] Callable Objects
Five kinds of callable objects: Functions Pointers to functions Objects of a class that overloads () ...
- c++11 Using Callable Objects, std::thread, std::bind, std::async, std::call_once
- is_callable Callbacks / Callables What is a “callable”? 可调用 回调函数
PHP: Callback / Callable 类型 - Manual https://www.php.net/manual/zh/language.types.callable.php Callb ...
- C++11语法糖
1.constexpr变量:声明为constexpr的变量一定是一个常量,新标准允许定义一种特殊的constexpr函数使得编译时就可计算结果,这样就能用constexpr函数去初始化constexp ...
- 【翻译十九】-java之执行器
Executors In all of the previous examples, there's a close connection between the task being done by ...
- [Code::Blocks] Install wxWidgets & openCV
The open source, cross platform, free C++ IDE. Code::Blocks is a free C++ IDE built to meet the most ...
- C++11lambda表达式
[C++11lambda表达式] mutable 修饰符,用于修改[]中以值传递的变量,无mutable修饰符的话则不行. 使用示例: #include <vector> #include ...
- 在 tornado 中异步无阻塞的执行耗时任务
在 tornado 中异步无阻塞的执行耗时任务 在 linux 上 tornado 是基于 epoll 的事件驱动框架,在网络事件上是无阻塞的.但是因为 tornado 自身是单线程的,所以如果我们在 ...
- Java Concurrency - 线程执行器
Usually, when you develop a simple, concurrent-programming application in Java, you create some Runn ...
随机推荐
- 浅谈Android开机启动速度优化(含应用程序启动速度优化)
众所周知Android开机启动速度较慢,于是如何加快启动速度便成为一个值得讨论的问题. 在查阅过许多资料后(特别是Google Group的android-platform),我整理总结出下面几点基本 ...
- 【JZOJ4895】【NOIP2016提高A组集训第16场11.15】三部曲
=v= 因为外来的入侵,国王决定在某些城市加派士兵.所有城市初始士兵数量为0.当城市 被加派了k名士兵时.城市i的所有子城市需要被加派k+1名士兵.这些子城市的所有子城市需要被加派k+2名士兵.以此类 ...
- Hibernate→ 《Hibernate程序开发》教材大纲
Hibernate ORM 概览 Hibernate 简介 Hibernate 架构 Hibernate 环境 Hibernate 配置 Hibernate 会话 Hibernate 持久化类 Hib ...
- day39 07-Spring的AOP:自动代理
带有切点的切面或者是不带有切点的切面配置一个类就要配置一段生成代理的代码,这样太麻烦了. 选中orderDao右键watch JDK动态代理是先创建被代理对象,然后在创建代理对象的时候传入被代理对象. ...
- hdu 1272 使用set和并查集
http://acm.hdu.edu.cn/showproblem.php?pid=1272 这道题就是求图是不是连通无环,我觉得其实就是看看图是不是一棵最小生成树. 所以要是图满足条件,就必然有n个 ...
- dsadsa
1.Swift预览 一般来说,编程语言教程中的第一个程序是在屏幕上打印“Hello, world”.在 Swift 中,可以用一行代码实现: println("Hello, world&qu ...
- hdu1525 博弈
/* n%m==0 n状态 n>=2*m 先手决定谁来面对当前的状态,并且可以知道状态,所以先手必胜. */ #include<stdio.h> int min(int x,int ...
- 复习一下jdbc原始封装
JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.加载JDBC驱动程序: 在连接数据库之前,首先要加载想要连接的数据库的驱动到JVM(Java虚拟机), 这通过java.l ...
- 十年磨一剑,王坚自研的MaxCompute如何解决世界级算力难题
摘要: 2009年这项关于大数据的技术长征开始.王坚带队,目标是自研大数据计算平台MaxCompute统一阿里巴巴内部的数据和大数据计算体系. 大数据时代,随着企业数据规模的急剧增长,传统软件已无法承 ...
- 创建ros消息时出现:Unable to load msg [planning/Num]: Cannot locate message [Num]: unknown pack.....
创建ros消息可参考创建ROS消息和ROS服务. 按照这个教程进行创建的过程中出现了如下错误: Unable to load msg [msgs/locate]: Cannot locate mess ...