function Foo () { getName = function() { console.log(1) } return this }

Foo.getName = function () { console.log(2) } Foo.prototype.getName = function () { console.log(3) } var getName = function () { console.log(4) } function getName () { console.log(5) }

Foo.getName() //2

getName() // 4

Foo().getName() // 1 getName() // 1

new Foo.getName() // 2 new Foo().getName() // 3 new new Foo().getName() //3

/ * * *

  • GetName -> func ->2 prototype BBBFFF000
  • BBBFFF000 includes constructor -> Foo and getName: func -> 3
  • getName => func -> 5
  • And then the code executes
  • GetName = func ->4 (!!!! Here I don’t understand)
  • Foo. GetName () takes func of 2 in AAAFFF000
  • GetName () executes the current global 4
  • Foo().getName() the execution Foo() first executes when a normal function executes we create an execution context getName this is not a private variable, looking for the parent scope, so the global scope is changed to func-> 1 (!!!!) So Foo() returns the window and windoww.getName() returns the window 1
  • Then the global getName() execution remains 1
  • You can also check new implementation and difference (!!!!)
  • And then new foo.getName(), which takes precedence, if you look down at the website, where new has no argument of 18 foo.getName() is 19, so do this first and then analyze foo.getName() which takes the AAAFFF000 Func is 2 so this is now new func-> 2 (!!!! So this is 2
  • And then new Foo().getName(), you can look down at the website and you can see that new doesn’t have an argument of 19 foo.getName() is 19 so it’s executed from left to right so the method that creates an instance of Foo and then calls that instance is a prototype method The prototype method is func -> 3 so this is 3
  • And then finally new new Foo().getName() this is the same thing new has no arguments 18 new has arguments 19 the function executes 19 so first new Foo().getName() this is func->3 so new func->3 It’s still 3

* /

// js calculates the priority of a website // developer.mozilla.org/en-US/docs/…