K
K
Kerrik Sun2021-07-05 12:35:28
JavaScript
Kerrik Sun, 2021-07-05 12:35:28

Why does it return false?

Here is the code:

function Func() {
    this.name = 'Eva',
        this.surname = 'Li'
};

console.log(Func.prototype == constructor.Func); //false


60e2d24054d79220396398.png
How can it produce falseif the constructor function Funcreally contains a property prototype, which contains a property constructor, which in turn contains a reference to the same constructor function Func?

How can that be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-07-05
@Eva25

Kerrik Sun , well, you can't not know (not understand) the language so much ...
You are referring to the variable constructor. I suspect that you are doing this in the browser console and this variable was never declared, so JS will give you a property constructorof the global object. In this case, it will be window.constructorwhich, of course, has nothing to do with your Func function.
And in any case, constructorit makes sense to look at an instance of an object, and not at a class.

let f = new Func();
console.log(f.constructor === Func) // true

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question