我一直在IE8中收到Object.create错误

时间:2015-08-28 09:21:34

标签: javascript angularjs internet-explorer-8 bower vis.js

我有一个使用vis.js的AngularJs网络应用程序,它与IE9 +兼容,但我试图让这个网络应用程序与IE8兼容,用户可以使用更少的功能,因为我必须

我包含以下库来处理常见的IE8兼容性问题:

<!--[if lte IE 9]>
      <script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.7.1/modernizr.min.js"></script>
      <script type='text/javascript' src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
      <script type='text/javascript' src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js"></script>
      <script type='text/javascript' src="scripts/eventShim.js"></script>
      <script>
// here I create the elements for all the custom directives
        document.createElement('custom-handler');
        document.createElement('custom-info');
        document.createElement('custom-data');
        document.createElement('custom-param');
        document.createElement('custom-rel');
        document.createElement('custom-panel');

        // Optionally these for CSS
        document.createElement('ng:include');
        document.createElement('ng:pluralize');
        document.createElement('ng:view');
        document.createElement('ng:style');
        document.createElement('ng:class');
      </script>
    <![endif]-->

然后使用凉亭:

<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
    <script src="bower_components/es5-shim/es5-shim.js"></script>
    <script src="bower_components/json3/lib/json3.js"></script>
...
<!-- endbower -->
<!-- endbuild -->

bower.json 中定义的库的显着版本:

"angular": "1.2",
"jquery": "1.11.2",
"json3": "~3.3.2",
"es5-shim": "~4.1.11",
"bootstrap-sass-official": "~3.3.5",
"angular-animate": "~1.2.0",
"angular-cookies": "~1.2.0",
"angular-resource": "~1.2.0",
"angular-route": "~1.2.0",
"angular-sanitize": "~1.2.0",
"angular-touch": "~1.2.0",
"angular-bootstrap": "0.12.0",
"vis": "~3.7.2",
"string": "~3.0.0",
"components-font-awesome": "~4.4.0",
"jquery-ui": "~1.11.4"
  

问题

尽管有上述所有设置,但当我使用IE8访问我的网络应用程序时,我在控制台中收到以下错误:

Object doesn't support this property or method        vis.min.js, line 29 character 1204

通过单击它,控制台将光标放在以下代码行的开头:

s.prototype=Object.create(o.prototype),s.prototype.redraw=function(...

即使我评论使用vis.js的HTML部分,错误仍然存​​在。

在IE9 +中打开网络应用程序时,我无法在凉亭中找到包含vis.js库的方法,所以我的 B计划就是要摆脱与vis.js相关的错误,然后使web-app中使用此库的所有功能都不可用。

这种方法可行吗?

如果没有,我该如何解决?

1 个答案:

答案 0 :(得分:2)

  

在IE9 +中打开网络应用程序时,我无法在凉亭中找到包含vis.js库的方法

Bower 只能包含来源 对于这样的任务,创建了 gulp 例如,您的建筑物将存在这样的代码:

var gulp = require('gulp')
var bowerFiles = require('main-bower-files');
var gulpFilter = require('gulp-filter');
var gulpInject = require('gulp-inject');

gulp.task('wiredep', function() {
    var ie8Files = ['**/json3.js', '**/es5shim.js'];
    // the same as: var restFiles = ['*', '!**/json3.js', '!**/es5shim.js'];
    var restFiles = ['*'].concat(ie8Files.map(function(e) { return '!' + e;}));
    gulp.src('index.html')
    .pipe(gulpInject(gulp.src(bowerFiles(), {read: false}).pipe(restFiles))
    .pipe(gulpInject(gulp.src(bowerFiles(), {read: false}).pipe(ie8Files),
                    {starttag: '<!--[if lt IE 9]>', endtag: '<![endif]-->'})
    .pipe(gulp.dest('dist'));
});

like here

或者正如你所说的计划B:

您可以为您的代码编写所有周期:

if (!Object.create) {
    Object.create = function(o, properties) {
        if (typeof o !== 'object' && typeof o !== 'function') throw new TypeError('Object prototype may only be an Object: ' + o);
        else if (o === null) throw new Error("This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.");

        if (typeof properties != 'undefined') throw new Error("This browser's implementation of Object.create is a shim and doesn't support a second argument.");

        function F() {}

        F.prototype = o;

        return new F();
    };
}

like here

对于我的观点,你应该添加一个gulp结构。