【问题标题】:I keep getting Object.create error in IE8我在 IE8 中不断收到 Object.create 错误
【发布时间】:2015-08-28 09:21:34
【问题描述】:

我有一个使用 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 部分,错误仍然存​​在。

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

这种方法可行吗?

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

【问题讨论】:

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


    【解决方案1】:

    当 web 应用在 IE9+ 中打开时,我无法在 bower 中找到包含 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 结构。

    【讨论】:

    • 您好 Illia,我正在使用 Grunt,您知道如何在 Grunt 中实现基于 Gulp 的解决方案吗?对于 B 计划,我遇到了相同的 Object.create polyfill,并且知道那将是我的王牌;但是,我应该将其包含在 index.html 页面内的 &lt;script&gt; 中,还是应该将其包含在单独的 .js 文件中?
    • 我想你的工作不是让 IE 表现得像它不应该表现的那样。 es5-shim 到目前为止还不起作用,这很奇怪。但是在项目中真正添加一个 gulp 怎么样?或者它只是不是一种选择?
    • 它很容易,您不必将一个翻译成另一个,使用插件grunt-gulp
    • 我很欣赏这个建议,但我似乎还有另一个王牌可以留在这里,因为我真的应该能够使用我所拥有的来解决这种情况,再次因为我有这样做
    • plan B 怎么样,我更喜欢 html 包含 html(ok 或模板,你好 angular)和 js 包含 js 的方式。许多项目都有一些utils.js 或类似的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多