On line 1, your object literal is interpreted literally and instantiated, as you usually expected.
While in line 5, your object literal is interpreted literally, but passed to the Object.create function, where the object instance is considered as a “property object containing property descriptors”.
Since the Object.create function expects the second parameter to follow the "Property Object" convention, your second parameter (on line 8) is invalid (causing a type error in Chrome).
The following snippet can help illustrate:
var PrototypeObj = { item: 'xxx' }; var PropertiesObj = { propertyDescriptor1: { value: "prop1value", writable: true, enumerable: true, configurable: true }, propertyDescriptor2: { value: "prop2value", writable: true, enumerable: true, configurable: true } }; var Obj = Object.create(PrototypeObj, PropertiesObj);
These articles are discussed in more detail: Object.create , Object.defineProperty .
source share