zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    chown更改文件和目录的所有者
    常量指针和指向常量的指针
    声明,有人破解我的mmsplayer,声称开源的mms
    声明,有人破解我的mmsplayer,声称开源的mms
    慎用mysql的utf8unicode
    慎用mysql的utf8unicode
    在 Ubuntu 下使用 Android NDK r4b 编译 FFmpeg 0.6.3
    skia 生成 vs2008工程
    mmsPlayer 2.0 将开源java部分
    skia 生成 vs2008工程
  • 原文地址:https://www.cnblogs.com/tsai-87/p/10863791.html
Copyright © 2011-2022 走看看