I have a Foo constructor like this:
function Foo(params) {
this.x = params.x + 5;
...
}
Foo is called like this:
var foo = new Foo(someObject);
I would like to check the contents of params in Foo's constructor, and if something is wrong (e.g. params.x is not a number, or params.y is undefined), I would like foo to be null (which will mean that the Foo object wasn't created).
One option, I guess, is to throw an exception in the constructor and wrap the call for new Foo(someObject) with try..catch (or create a function like makeFoo that does so).
How would you suggest to handle this problem?