Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

javascript - Can't find variable: Promise on Safari

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);
    });
};
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...