【问题标题】:Why o.prototype.isPrototypeof is not a function, my javascript throws an exception为什么o.prototype.isPrototypeof不是函数,我的javascript抛出异常
【发布时间】:2016-08-17 03:43:12
【问题描述】:

我尝试了一段小代码:

function o(){};
var Derived = function () {}
Derived.prototype = o;
var o2 = new Derived();
console.log(o.prototype.isPrototypeof(o2));

最后一行抛出异常,表示:

console.log(o.prototype.isPrototypeof(o2));
                    ^
TypeError: o.prototype.isPrototypeof is not a function

这对我来说很奇怪,为什么 o 没有原型属性? 定义函数/新对象时,名称会自动绑定到原型属性吗?

【问题讨论】:

    标签: javascript function prototype


    【解决方案1】:

    您通常可以依赖 Javascript 方法和函数,这也不例外。

    方法是.isPrototypeOf()

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 2010-12-09
      • 1970-01-01
      • 2014-04-22
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多