javascript 对象不支持此属性或方法 EmberJs IE 8 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25760086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 04:57:39  来源:igfitidea点击:

Object doesn't support this property or method EmberJs IE 8 issue

javascriptember.jsinternet-explorer-8polyfillsie-compatibility-mode

提问by SharpCoder

I am getting following error on my IE 8 page (The page is running fine in other browsers).

我的 IE 8 页面出现以下错误(该页面在其他浏览器中运行良好)。

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; InfoPath.3)
Timestamp: Wed, 10 Sep 2014 06:48:45 UTC

Message: Object doesn't support this property or method
Line: 70532
Char: 5
Code: 0

When I checked the line 70532 in the file mentioned, i saw this code:

当我检查提到的文件中的第 70532 行时,我看到了以下代码:

if (!Object.create && !Object.create(null).hasOwnProperty) {
      throw new Error("This browser does not support Object.create(null), please polyfil with es5-sham: http://git.io/yBU2rg");
    }

What does it meant by Please polyfil with es5-sham:

Please polyfil with es5-sham是什么意思

 Please polyfil with es5-sham: http://git.io/yBU2rg

enter image description here

在此处输入图片说明

How can I fix this error.

我该如何解决这个错误。

回答by

Object.createis not supported in IE8, therefore your framework is asking you to "polyfil" it, which means you need to implement something which should have been supported natively, but for some reason, this particular environment doesn't know about it.

Object.createIE8 不支持,因此你的框架要求你“polyfil”它,这意味着你需要实现一些本应支持的东西,但由于某种原因,这个特定的环境不知道它。

It means, if you want to use Object.createyou have to implement it yourself. Fortunatelly, you don't have to do much, the url ( https://github.com/es-shims/es5-shim/blob/master/es5-sham.js) points to a file which contains the neccesary polyfills. Just run that script before your framework script does.

这意味着,如果你想使用它,Object.create你必须自己实现它。幸运的是,你不必做太多,url ( https://github.com/es-shims/es5-shim/blob/master/es5-sham.js) 指向一个包含必要 polyfills 的文件。只需在您的框架脚本运行之前运行该脚本。

update:
This line seems broken to me: !Object.create && !Object.create(null).hasOwnProperty.
If Object.createis not there, calling it like Object.create(null)should throw an error, but I think it should be something like 'undefined is not a function'.

更新:
这条线似乎打破对我说:!Object.create && !Object.create(null).hasOwnProperty
如果Object.create不存在,则调用它Object.create(null)应该会引发错误,但我认为它应该类似于“未定义不是函数”。

回答by SharpCoder

I found another polyfil which is working in my scenario. I found the answer at this link.

我找到了另一个在我的场景中工作的 polyfil。我在这个链接上找到了答案。

I am adding code form that link

我正在添加链接的代码表单

if (!Object.create) {
    Object.create = function(proto, props) {
        if (typeof props !== "undefined") {
            throw "The multiple-argument version of Object.create is not provided by this browser and cannot be shimmed.";
        }
        function ctor() { }
        ctor.prototype = proto;
        return new ctor();
    };
}

adding this code seems to be doing trick for me. Only change I made is, I commented the code where exception is thrown as it is resulting in another error.

添加此代码似乎对我有用。我所做的唯一更改是,我注释了抛出异常的代码,因为它会导致另一个错误。