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.

2
  • 2
    F is the constructor function, f is an instance. Methods attached to the constructor function are not available to the instances. Commented Jan 13, 2020 at 1:25
  • An object's prototype carries the shared properties and methods of all instances of the object. Commented Jan 13, 2020 at 1:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.