When dealing with Object.create()
I came across this question and in summary it mentions:
Object.cre
how did programmers accomplish this task prior to ES5
Not at all. There had been property attributes in ES3, but there was no way to set them. There was no Object.create
as well. There just had been .propertyIsEnumerable() to get the DontEnum
flag.
what would be a better/alternative implementations of initializing an object based on on a set of passed properties without utilizing the second parameter?
Use an extend
function. Example with jQuery:
var instance = $.extend(Object.create(template), {options:arrayOfOptions});
Example with self-made helper function:
function createAndExtend(proto, props) {
var o = Object.create(proto);
for (var p in props)
o[p] = props[p];
return o;
}
var instance = createAndExtend(template, {options:arrayOfOptions});
You hardly ever need property descriptors anyway.