tags:

views:

60

answers:

2
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 'function'.

Is there a case when the constructor of an object will NOT be 'function' ?

+6  A: 

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

See: http://www.w3schools.com/jsref/jsref%5Fconstructor%5Fmath.asp

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

The Mozilla documentation is even clearer:

Returns a reference to the Object function that created the instance's prototype. Note that the value of this property is a reference to the function itself, not a string containing the function's name

Philippe Leybaert
A: 

An object constructor is merely a regular JavaScript function, so it's just as robust (ie: define parameters, call other functions etc). The difference between the two is that a constructor function is called via the new operator

Read

Object Constructor and prototyping

rahul