Polyfill for Object.create和浏览器支持代码

时间:2017-07-23 10:30:12

标签: javascript browser

我将这些代码行用作Javascript Polyfill,以支持最旧的浏览器来理解Object.create,但我真的不知道代码是怎么做的 的工作原理。



// polyfill
if (!Object.create) {
  Object.create = function (o) {
    if (arguments.length > 1) {
      throw new Error('Object.create implementation'
      + ' only accepts the first parameter.');
    }
    function F() {}
    F.prototype = o;
    return new F();
  };
}




0 个答案:

没有答案
相关问题