In a constructor object in JS, if it is created without a new keyword, the 'this' variable is a window reference instead of an object. Is it a particularly wise idea to try and discover it?
function MyObject ()
{
if (this === window) {
alert('[ERROR] Oopsy! You seem to have forgotten to use the "new" keyword.');
return;
}
}
obj = MyObject()
source
share