2 * Simplified version of es5-sham#Object-create that also works around a bug
3 * in the actual es5-sham: https://github.com/es-shims/es5-shim/issues/252
6 * - Support empty inheritance via `Object.create(null)`.
7 * - Support getter and setter accessors via `Object.create( .., properties )`.
8 * - Support custom property descriptor (e.g. writable, configurtable, enumerable).
9 * - Leave behind an enumerable "__proto__" all over the place.
11 * @author Timo Tijhof, 2014
15 // http://es5.github.com/#x15.2.3.5
16 if ( !Object
.create
) {
18 var hasOwn
= Object
.hasOwnProperty
,
19 // https://developer.mozilla.org/en-US/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug
20 // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
21 isEnumBug
= !{ valueOf
: 0 }.propertyIsEnumerable( 'valueOf' );
23 // Reusable constructor function for Object.create
26 function defineProperty( object
, key
, property
) {
27 if ( hasOwn
.call( property
, 'value' ) ) {
28 object
[ key
] = property
.value
;
30 object
[ key
] = property
;
34 Object
.create
= function create( prototype, properties
) {
37 if ( prototype !== Object( prototype ) ) {
38 throw new TypeError( 'Called on non-object' );
41 Empty
.prototype = prototype;
44 if ( properties
!== undefined ) {
46 for ( key
in properties
) {
47 if ( hasOwn
.call( properties
, key
) ) {
48 defineProperty( object
, key
, properties
[ key
] );
52 Object
.keys( properties
).forEach( function ( key
) {
53 defineProperty( object
, key
, properties
[ key
] );