One case where a constructor property is convenient (or would be if it were reliable) is where the function should know the type of argument that it passed, for example.
function foo(arg) { if ( /* if arg is an array */ ) { // deal with array } else if ( /* if arg is an object */ ) { // deal with object } }
If an array or object is passed to the above function, then typeof will return the object in both cases. The constructor property can be used:
if ( arg.constructor == Array )
But this does not work if the array is created in another frame where the test is running (i.e. its Array constructor is another object of the Array function in the test area).
So, if you exclude frames (or other cases where the area is a problem), then the constructor property is suitable for this.
But this does not exclude that the general problem of constructor properties is the ability to write (and therefore can be installed on anything) and cases where the prototype chain is more trivial.
source share