1a.
01 Function.prototype.method = function foo() {}
02 Function.prototype.method === Function.method;
This is adding a property to the object that the property of the prototypeembedded object points to Function.
Function - - "".
Function - , - .
Function , prototype. -.
1 method Function.prototype, - foo ( ).
2 Function.prototype.method ( 1) , method, - Function. JavaScript , .
, 2 Function.prototype.method , method Function.prototype.
2 Function.method Function; , , Function.__proto__ ( ). __proto__ JavaScript prototype , . , ( !), , Function " " ( Function , userland), , prototype __proto__ - - .
, method __proto__, , Function.prototype, method. :
02 Function.prototype.method === Function.method;
1b.
01 function MyClass() {}
02 MyClass.prototype.method = function foo() {}
03 MyClass.prototype.method == MyClass.method
04
, , Function , 1a.
( 1 ), MyClass prototype , .
2 method foo.
3 foo method MyClass. , method MyClass . MyClass, , __proto__, method ( , ). , 1a ( JavaScript), __proto__ prototype , . MyClass Function, MyClass.__proto__ Function.prototype ( , MyClass.prototype). . method, undefined.
:
MyClass.prototype.method == MyClass.method // false
2.
Object instanceof Function
- -- . , .
Function instanceof Object
instanceof - , true, RHS LHS. :
Function.__proto__ -> Function.prototype
Function.prototype -> function f() {}
f.__proto__ -> {}
, , , Object f.__proto__ ( f). :
Function instanceof Object
Object instanceof Object
, Object.prototype Object.
Object.__proto__ -> Function.prototype
Function.prototype.__proto__ -> {}
So Function.prototype.__proto__ === Object.prototype, :
Object instanceof Object
Function instanceof Function
, 1a.