gpt4 book ai didi

javascript - 我在 IE8 中不断收到 Object.create 错误

转载 作者:行者123 更新时间:2023-11-30 16:39:09 27 4
gpt4 key购买 nike

我有一个使用 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]-->

然后使用 bower:

<!-- 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"

The problem

尽管进行了上述所有设置,当我使用 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+ 中打开网络应用程序时,我无法在 Bower 中找到包含 vis.js 库的方法,所以我的B 计划 只是摆脱了与 vis.js 相关的错误,然后使使用此库的网络应用程序中的所有功能不可用。

这种方法可行吗?

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

最佳答案

I wasn't able to find a way in bower to include the vis.js library just when the web-app is opened in IE9+

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 结构。

关于javascript - 我在 IE8 中不断收到 Object.create 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com