15.2.3.7 Object.defineProperties(O, Properties)

2010-07-04

object Object.defineProperties(O:object, Properties:object|mixed) throws TypeError

Set zero or more properties to the PD supplied in Properties. The key serves as the property name and the value is the PD. Properties is coerced into an object.

Code: (Meta Ecma)
Object.defineProperties = function(O,Properties){
if (Type(O) != 'Object') throw TypeError;
var props = ToObject(Properties);
var names = GetEnumerableProperties(Properties); // ? need to define this in meta
var descriptors = [];
for (P in names) { // order is important here...
var descObj = props.[[Get]](P);
var desc = ToPropertyDescriptor(descObj);
descriptors.push(desc);
}
for (desc in descriptors) { // preserve order
O.[[DefineOwnProperty]](P, desc, true);
}
return O;
}

The specification notes that if the implementation uses a specific order to enumerate, the same order should be used to create the names.