【问题标题】:The prototype (parent class) of a prototype object in Javascript?Javascript中原型对象的原型(父类)?
【发布时间】:2015-11-05 10:59:02
【问题描述】:

在Javascript中,我可以通过

获得Array对象的原型
var arr_prototype = Array.prototype

据我了解,这个 Array.prototype 类似于 OOP 中的类。

在纯 OOP 语言中,Array 类可能继承自 Iterable 类,Iterable 类可能继承自 Object 类。

所以我希望通过评估表达式arr_prototype.prototype 来查看arr_prototype 的父类。

但是,它返回undefined。有人对此有想法吗?

【问题讨论】:

  • 你可以得到prototype属性,它只从function引用原型,否则你可以简单地尝试用这个名字获取属性。要从具体对象获取原型,您可以使用 Object.getPrototypeOf 函数
  • 当一切都失败时,read the spec。 Array.prototype 继承自 Object.prototype,但是是 Array 的一个实例。它是一个Array exotic object,与标准的 Array 对象有点不同。

标签: javascript oop prototype prototype-programming


【解决方案1】:
Object.getPrototypeOf(arr_prototype );

prototype 属性不属于它属于构造函数的实例

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多