Typeof object.constructor always returns a function. It's true?

function Person(name){
 this.name = name;
}

p = new Person('John');
log(typeof p.constructor);

var f = {};
log(typeof f.constructor);

var f2 = new Object();
log(typeof f2.constructor);

All three log statements show a 'function'.

Is there a case where the constructor of an object will NOT be a "function"?

+3
source share
2 answers

A constructor is a function in javascript, by definition . Thus, a type will always be a "function".

See: http://www.w3schools.com/jsref/jsref_constructor_math.asp

"The constructor property is a reference to the function that created the object.

Mozilla's documentation is even more clear:

Object, . , , ,

+6

- JavaScript, (.. , ..). , -

Read

0

Source: https://habr.com/ru/post/1718287/


All Articles