Object.create not supported in ie8

前端 未结 3 454
北恋
北恋 2020-12-09 09:36

I came across an issue with a plugin that uses object.create in jquery to create a date dropdown. I just noticed in IE 8 that it is throwing an error of:

SC         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 09:44

    This will make Object.create() work in IE 8.

    I tried the shim/sham but that didn't work for me.

    if (typeof Object.create !== 'function') {
     Object.create = function(o, props) {
      function F() {}
      F.prototype = o;
    
      if (typeof(props) === "object") {
       for (prop in props) {
        if (props.hasOwnProperty((prop))) {
         F[prop] = props[prop];
        }
       }
      }
      return new F();
     };
    }
    

提交回复
热议问题