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 ...
随机推荐
- MSSQL 为db创建user
use [IBatisNet]GO if not exists (select * from master.dbo.syslogins where loginname = N'IBatisNet')B ...
- 利用JDBC连接Oracle数据库(转)
http://blog.csdn.net/wahaha1_/article/details/8512438 JDBC是Sun公司制定的一个可以用Java语言连接数据库的技术. 一.JDBC基础知识 J ...
- 19-2 from和modelform的用法和介绍
一 form 1. form的作用 1. 生成HTML代码 2. 帮我们做数据有效性的校验 3. 保留上次输入内容,显示错误提示 2. form组件校验数据有效性 1. 内置的校验规则 1. re ...
- Kernal Panic - Not syncing : VFS: unable to mount root fs on unknown-block
升级了一下centos6.5 执行了 yum -y update reboot 出现了以下问题: Kernal Panic - Not syncing : VFS: unable to mount r ...
- 2019.9.10附加题while练习
题目:企业发放的奖金根据利润提成.利润(I)低于或等于10万元时,奖金可提10%:利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%:20万到40万之 ...
- Directx11学习笔记【八】 龙书D3DApp的实现
原文:Directx11学习笔记[八] 龙书D3DApp的实现 directx11龙书中的初始化程序D3DApp跟我们上次写的初始化程序大体一致,只是包含了计时器的内容,而且使用了深度模板缓冲. D3 ...
- Java练习 SDUT-3849_分数四则运算
分数四则运算 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 编写程序,实现两个分数的加减法 Input 输入包含多行数 ...
- 从零学React Native之08Image组件
开发过程中, 几乎每个项目都会用到图片. RN就是通过Image组件显示图片.既可以加载网络图片,也可以加载本地资源图片. Image组件必须在样式中声明图片的款和高.如果没有声明,则图片将不会被呈现 ...
- HDU 1081 To The Max【dp,思维】
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...
- 复杂SQL示例 (排行榜需求)
公司项目要求做出排行榜,根据六组数据依次排行,关联多表,SQL记录下来方便日后查看 " ?><!DOCTYPE mapper PUBLIC "-//mybatis.or ...