ECMAScript-regrets
ECMAScript-regrets copied to clipboard
Easy to accidentally "Call" functions that are really Constructors
If you write a constructor function:
function House(address, style) {
this.location = address;
this.style = style || 'ranch';
}
var home = House(); // oops! redirected the browser.
You can call it as a function accidentally, and there is no error. (ES5 Strict mode helps a little, by making this
be undefined, so it will at least throw.)
This isn't a simple fix, as there are times when you want to call a constructor as a function. But it would be better if this were some kind of error.