代码片段一:

alert(Function instanceof Object); // true
alert(Object instanceof Function); // true

Function 是 Object 的实例,Object 也是 Function 的实例,好“纠缠”的关系。

代码片段一:

alert(Object.forEach); // undefined

Function.prototype.forEach = function(object, block, context) {
    for (var key in object) {
        if (typeof this.prototype[key] == "undefined") {
            block.call(context, object[key], key, object);
        }
    }
};

alert(Object.forEach);
alert(Function.forEach);
alert(Object.forEach === Function.forEach); // true

给 Function 设置的原型方法 forEach,“有趣”的是 Object 也能够获取。

至于为什么可以从 JavaScript Object layout 图中获取部分解答:

与 Function 和 Object 相关的有趣代码

 

相关文章:

  • 2022-02-22
  • 2021-07-18
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-02-23
猜你喜欢
  • 2021-09-06
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-12-30
  • 2021-12-24
相关资源
相似解决方案