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.

最新文章

  1. angularjs集成requirejs
  2. 以纯面向对象的JS编写最基本的数据字典案例
  3. Hadoop技术内幕-第一章 阅读原代码前的准备
  4. z-index 用法
  5. MySQL多表连接
  6. .frm文件
  7. html语言中的meta元素
  8. JavaScript--格式化当前时间
  9. SqlServer排序(null值,和非空值排列顺序)
  10. Isomorphic Strings leetcode
  11. RADIUS and IPv6[frc-3162译文]
  12. cve-2017-8464 复现 快捷方式远程代码执行
  13. gcc编译相关tips
  14. Java学习笔记18---final关键字修饰变量、方法及类
  15. Zabbix实战-简易教程--低层次发现(LLD)
  16. Swift基础之UITextField
  17. SQL语句 拆分某些字段,一行变多行
  18. Centos7 安装PhantomJS
  19. ESLint 配置说明
  20. foreach嵌套遍历循环的问题

热门文章

  1. 几道莫名AC的并查集题
  2. python 字符串匹配的应用
  3. 使用Velero Restic快速完成云原生应用迁移至ACK集群
  4. 免费报名 | 汇聚HBase&大数据最前沿 Apache HBaseConAsia2019盛会火热来袭
  5. python 缓冲区 subprocess 黏包 黏包解决方案
  6. iOS 通知观察者的被调函数不一定运行在主线程
  7. AT2346 No Need
  8. SDUT-3344_数据结构实验之二叉树五:层序遍历
  9. Istio on ACK集成生态(1): 集成TSDB助力可观测性存储
  10. 「BZOJ2510」弱题