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的更多相关文章

  1. [c++] Callable Objects

    Five kinds of callable objects: Functions Pointers to functions Objects of a class that overloads () ...

  2. c++11 Using Callable Objects, std::thread, std::bind, std::async, std::call_once

  3. is_callable Callbacks / Callables What is a “callable”? 可调用 回调函数

    PHP: Callback / Callable 类型 - Manual https://www.php.net/manual/zh/language.types.callable.php Callb ...

  4. C++11语法糖

    1.constexpr变量:声明为constexpr的变量一定是一个常量,新标准允许定义一种特殊的constexpr函数使得编译时就可计算结果,这样就能用constexpr函数去初始化constexp ...

  5. 【翻译十九】-java之执行器

    Executors In all of the previous examples, there's a close connection between the task being done by ...

  6. [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 ...

  7. C++11lambda表达式

    [C++11lambda表达式] mutable 修饰符,用于修改[]中以值传递的变量,无mutable修饰符的话则不行. 使用示例: #include <vector> #include ...

  8. 在 tornado 中异步无阻塞的执行耗时任务

    在 tornado 中异步无阻塞的执行耗时任务 在 linux 上 tornado 是基于 epoll 的事件驱动框架,在网络事件上是无阻塞的.但是因为 tornado 自身是单线程的,所以如果我们在 ...

  9. Java Concurrency - 线程执行器

    Usually, when you develop a simple, concurrent-programming application in Java, you create some Runn ...

随机推荐

  1. openssl生成证书 - CSDN博客

    大家都可以生成公钥.私钥对,无法确认公钥对到底是谁的. 如果能够确定公钥到底是谁的,就不会有这个问题了.例如,如果收到“黑客”冒充“服务器”发过来的公钥,经过某种检查,如果能够发现这个公钥不是“服务器 ...

  2. Kubernetes Ingress 日志分析与监控的最佳实践

    摘要: Ingress主要提供HTTP层(7层)路由功能,是目前K8s中HTTP/HTTPS服务的主流暴露方式.为简化广大用户对于Ingress日志分析与监控的门槛,阿里云容器服务和日志服务将Ingr ...

  3. ThinkPHP5.0中的build.php自动生成所需的目录结构的详细方法

    一.来到根目录下,找到bulid.php文件进行改写. 改写方法:保留常用的目录结构,其余按照需求改吧! 二.复制一份build.php文件到application目录下 此时根目录下的bulid.p ...

  4. 第一份Markdown。。。。。菜鸟给跪了

    #First Markdown ##Hello World ###Ahaha - Python - Ruby - C++ - Haskell - C - Java 1. C 2. C++ 3. C# ...

  5. 2018-8-29-Roslyn-通过-Target-修改编译的文件

    title author date CreateTime categories Roslyn 通过 Target 修改编译的文件 lindexi 2018-08-29 09:10:46 +0800 2 ...

  6. python 使用自定义的类方法

  7. pl/sql基础知识—定义并使用变量

    n  介绍 在编写pl/sql程序是,可以定义变量和常量:在pl/sql程序中包括有: ①标量类型(scalar) ②复合类型(composite) ③参照类型(reference) ④lob(lar ...

  8. js单选按钮的默认值

    function SelectWindow(str) { initradio('PhysiotherapyOptionsTable.Sex',sex);       } function initra ...

  9. request header....

    root@xxx# curl -i --get --include 'http://ali-barcode.showapi.com/barcode?code=6938166920785' -H 'Au ...

  10. [软考]之软件过程模型II 标签: 软件工程 2015-11-01 11:52 1612人阅读 评论(22) 收

    上一篇博客总结了瀑布模型/V模型/增量模型这三种软件模型,然而我们还有一个很重要的问题忘了回答,那就是,什么是软件过程模型? 什么是软件过程模型? 软件过程是软件开发与维护的工作流程和工艺流程,是软件 ...