123456789101112131415161718192021222324252627282930313233343536373839404142 |
- // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
- var anObject = require('./_an-object')
- , dPs = require('./_object-dps')
- , enumBugKeys = require('./_enum-bug-keys')
- , IE_PROTO = require('./_shared-key')('IE_PROTO')
- , Empty = function(){ /* empty */ }
- , PROTOTYPE = 'prototype';
- // Create object with fake `null` prototype: use iframe Object with cleared prototype
- var createDict = function(){
- // Thrash, waste and sodomy: IE GC bug
- var iframe = require('./_dom-create')('iframe')
- , i = enumBugKeys.length
- , lt = '<'
- , gt = '>'
- , iframeDocument;
- iframe.style.display = 'none';
- require('./_html').appendChild(iframe);
- iframe.src = 'javascript:'; // eslint-disable-line no-script-url
- // createDict = iframe.contentWindow.Object;
- // html.removeChild(iframe);
- iframeDocument = iframe.contentWindow.document;
- iframeDocument.open();
- iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
- iframeDocument.close();
- createDict = iframeDocument.F;
- while(i--)delete createDict[PROTOTYPE][enumBugKeys[i]];
- return createDict();
- };
- module.exports = Object.create || function create(O, Properties){
- var result;
- if(O !== null){
- Empty[PROTOTYPE] = anObject(O);
- result = new Empty;
- Empty[PROTOTYPE] = null;
- // add "__proto__" for Object.getPrototypeOf polyfill
- result[IE_PROTO] = O;
- } else result = createDict();
- return Properties === undefined ? result : dPs(result, Properties);
- };
|