It really tastes good. Thus:
var anotherVariable = new someObjectType({ property1: "Some value for this named property", property2: "This is the value for property 2" });
... it is usually better if there are more than 2/3 of the arguments, as it helps readability and simplifies the elimination of an optional problem with the argument ( fn(null,null,null,123') ).
Another consideration is performance. Passing arguments in the usual way will be faster, but this increase in speed becomes significant only in situations with high sensitivity.
Can I use this second way of instantiating an object type variable that was defined using the "classic" way of defining an object type using an implicit constructor?
Not easy. If you want to instantiate a constructor using a hash instead of simply passing arguments, and you have no control over the source, you can wrap it:
var _constructor = SomeConstructorFunction; SomeConstructorFunction = function(hash) { return new _constructor(hash.property1, hash.property2); };
I really would not recommend messing with third-party APIs just for the sake of style.
If I want to create an array of these objects, are there any other considerations?
How big is the array? Which array exactly? Performance may be worth attention ...
James
source share