最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't find variable: Promise on Safari - Stack Overflow

programmeradmin5浏览0评论

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 e up with this:

/

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);
    });
};

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 e up with this:

http://jsfiddle/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);
    });
};
Share Improve this question edited Dec 25, 2021 at 5:29 Peyman Mohamadpour 18k24 gold badges92 silver badges101 bronze badges asked Mar 17, 2014 at 18:26 Robert PetzRobert Petz 2,7644 gold badges24 silver badges53 bronze badges 4
  • 1 Hmm, I just changed the code to use the fully qualified name: new Ember.RSVP.Promise(...) and it appears to fix it in Safari on my macbook...That sucks as the documentation on Ember's site doesn't use the fully qualified name – Robert Petz Commented Mar 17, 2014 at 19:21
  • 1 maddening, actually. Thanks for posting the solution – panzhuli Commented Mar 23, 2014 at 15:03
  • Ran into this myself, trying to figure out exactly what's responsible for this behavior. Are you using ember-cli or just ember? – gregates Commented Jul 28, 2014 at 18:54
  • I'm just using ember myself – Robert Petz Commented Jul 28, 2014 at 21:59
Add a ment  | 

2 Answers 2

Reset to default 14

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.

According to this, there are no promises for iOS Safari 7.1, or Safari 7.

However, they will be getting them in iOS Safari 8 and Safari 8.

发布评论

评论列表(0)

  1. 暂无评论