0

enter image description here

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

As the description above, i Confused abort the following: 1. why methodF stored in constructor? 2. why instance f can not access methodF? but F can access.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
  • 2
    `F` is the constructor function, `f` is an instance. Methods attached to the constructor function are not available to the instances. – VLAZ Jan 13 '20 at 01:25
  • An object's `prototype` carries the shared properties and methods of all instances of the object. – Randy Casburn Jan 13 '20 at 01:30

0 Answers0