首页 > 解决方案 > javascript 引用实例无法访问构造函数中的方法?

问题描述

在此处输入图像描述

function F(){
    // NOP
};
F.methodF = function(){
    // NOP
};
var f = new F();

f.__proto__
  {constructor: ƒ}
     constructor: ƒ F()
     methodF: ƒ ()
     length: 0
     name: "F"
     arguments: null
     caller: null
     prototype: {constructor: ƒ}
     __proto__: ƒ ()
     [[FunctionLocation]]: VM978:1
  [[Scopes]]: Scopes[1]
  __proto__: Object

F.methodF
   ƒ (){
    // NOP
   }

f.methodF
undefined

如上所述,我很困惑 abort 以下内容: 1. 为什么 methodF 存储在构造函数中?2. 为什么instance f不能访问methodF?但 F 可以访问。

标签: javascriptconstructorprototype

解决方案


推荐阅读