找不到变数:在Safari上的Promise [英] Can't find variable: Promise on Safari
问题描述
当我在iOS上运行7或Safari 7.0.2我在控制台上收到一条错误,指出在加载路由时出错:checkIfLoggedIn'
在消息中指定的成员不是路由,它是一种返回承诺的方法。当我调试ember代码来弄清楚出了什么问题,我发现它是拒绝承诺的原因是'无法找到变量:Promise'
我不能在这里发布我的网站的实际代码,所以我开始创建一个小提琴重现错误,我能够想出这一点:
http://jsfiddle.net/NQKvy/851/
这完全适用于桌面电脑(Windows 8.1和OS X Mavericks)的Chrome,但在iOS 7或Safari 7.0.2上,会向控制台引用以下错误:ReferenceError:无法找到变量:Promise'
任何人都有任何想法为什么这不工作?
要重述:
- 我已经在Chrome上测试了Windows 8.1和OS X小牛 - 它的工作原理
- 我已经在Chrome上进行了iOS测试, / li>
- 我已经在Safari上测试了iOS和OS X小牛,它不工作
- 我还没有在Android上测试(目前我无法访问任何设备)
这使我相信它是一个Safari错误(如果我记得正确)Chrome for iOS使用Safari控件来渲染页面而不是Chromium
这是我使用的代码生成错误:
App.ready = function(){
var asdf = new Promise(function(resolve){
var i = 1;
i ++;
resolve.call(this,i);
})然后(function(result){
alert('I:'+ result);
});
};
事实证明,在Safari上,您必须使用完全合格的创建承诺时的名称,否则将无法正常工作:
App.ready = function(){
var asdf = new Ember.RSVP.Promise(function(resolve){
var i = 1;
i ++;
resolve.call(this,i);
})then function(result){
alert('I:'+ result);
});
};
注意新的Ember.RSVP.Promise而不是新的Promise。这似乎为我解决了。
I have a site I'm working on that runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks)
When I run it on iOS 7 or Safari 7.0.2 I get an error to the console that states 'Error while loading route: checkIfLoggedIn'
the member it specifies at the message is not a route, it is a method that returns a promise. When I debug through the ember code to figure out what is going wrong I found that it is rejecting the promise with the reason of 'Can't find variable: Promise'
I can't post the actual code from my site here, so I set out to create a fiddle that reproduces the error and I was able to come up with this:
http://jsfiddle.net/NQKvy/851/
This runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks), but on iOS 7 or Safari 7.0.2 throws the following error to the console 'ReferenceError: Can't find variable: Promise'
Anyone have any ideas why this isn't working?
To recap:
- I have tested on Chrome for Windows 8.1 and OS X Mavericks - It works
- I have tested on Chrome for iOS and it does not work
- I have tested on Safari for iOS and OS X Mavericks and it does not work
- I have not tested on Android at all (I don't have access to any devices at this moment)
This leads me to believe that it is a Safari error as (if I recall correctly) Chrome for iOS uses a Safari control to render the page rather than Chromium
This is the code I'm using to generate the error:
App.ready = function() {
var asdf = new Promise(function (resolve) {
var i = 1;
i++;
resolve.call(this,i);
}).then(function (result) {
alert('I: ' + result);
});
};
Turns out that on Safari you must use the fully qualified name when creating a promise, otherwise it will not work:
App.ready = function() {
var asdf = new Ember.RSVP.Promise(function (resolve) {
var i = 1;
i++;
resolve.call(this,i);
}).then(function (result) {
alert('I: ' + result);
});
};
Note the 'new Ember.RSVP.Promise' instead of the 'new Promise'. This appears to fix it for me.
这篇关于找不到变数:在Safari上的Promise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!