Other than throwing an exception during the execution of an object's
constructor, is there any way to cancel creation of the object in such a
way that it leaves a reference to it null or undefined. That would enable
the simple test:
var ref = new someObject();
if( ref ) {
// Object created successfully
}
I know one could use state flags instead, but the object I have in mind
shouldn't exist if the arguments passed to it are incorrect (there is a
good reason, trust me).
[OT - Exceptions in general (including other languages)]
Some people seem to have issues concerning throwing an exception during
object construction to signify failure and instead prefer to use state
flags. Any thoughts either way?
[/OT]
By the way, it's not possible to have protected[1] members in JavaScript,
is it? Shame...
Many thanks,
Mike
[1] I do mean protected, not private.
--
Michael Winter
M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
constructor, is there any way to cancel creation of the object in such a
way that it leaves a reference to it null or undefined. That would enable
the simple test:
var ref = new someObject();
if( ref ) {
// Object created successfully
}
I know one could use state flags instead, but the object I have in mind
shouldn't exist if the arguments passed to it are incorrect (there is a
good reason, trust me).
[OT - Exceptions in general (including other languages)]
Some people seem to have issues concerning throwing an exception during
object construction to signify failure and instead prefer to use state
flags. Any thoughts either way?
[/OT]
By the way, it's not possible to have protected[1] members in JavaScript,
is it? Shame...
Many thanks,
Mike
[1] I do mean protected, not private.
--
Michael Winter
M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Comment