Why ** (Object .__ proto__ instanceof Function) ** === false?

why does the Object._proto_ instanceof function give me a lie?

alert(Object.__proto__ ); //  clearly Object.__proto__ is a function right?
alert(typeof Object.__proto__); // clearly Object.__proto__ is a function right?
alert(Object.__proto__ instanceof Function); // !
+3
source share
4 answers

Not all functions are created using the constructor Function. instanceofchecks if the given item was actually created by this particular function.

You get a similar effect in a browser environment when working with multiple windows. I mean, if you have a function fooin window A:

function foo(arg) {
    if (arg instanceof Array) {
        // It an array, do something
    }
}

... and you have the code in another window B that calls it:

opener.foo([]);

... , foo , arg - , ? , arg , Array , foo.

, : , ?

( ), . , ... ... ... ... , .


. , __proto__ JavaScript.

+4

:

Object.__proto__?

  • Function.prototype.

    Object.__proto__ === Function.prototype; // true
    

Object , Function.prototype.

(Function.prototype) , Function, , , " t , Object.protoype.

:

Object.__proto__ instanceof Function;   // false, which is equivalent to:
Function.prototype instanceof Function; // false

, Function.prototype Function.prototype:

Function.prototype.isPrototypeOf(Function.prototype); // false, equivalent to:
Object.prototype.isPrototypeOf.call(Function.prototype, Function.prototype);

, , , :

  • ( [[Call]]).

    typeof Function.prototype; // "function"
    
  • [[Class]] "Function".

    Object.prototype.toString.call(Function.prototype); // "[object Function]"
    
  • [[Prototype]] Object.prototype ( ).

    Object.prototype.isPrototypeOf(Function.prototype); // true
    
  • .

  • undefined.

  • length <<221 > .

  • [[Extensible]] true.

+3
alert(Object.__proto__ ); //  clearly Object.__proto__ is a function right?
alert(typeof Object.__proto__); // clearly Object.__proto__ is a function right?
alert(Object.__proto__ instanceof Function); // !

That is the function. However, this is not an object function . Therefore, instanceof returns false. Here you can read all about instanceof here .

+2
source

the image in this post will help you understand the relationship of the vs Object function

JavaScript object layout

0
source

All Articles