angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.8k stars 27.48k forks source link

Multiple Different Implementations of isPromiseLike() #13372

Open aebabis opened 8 years ago

aebabis commented 8 years ago

promises-aplus-test-adapter uses the following code to determine if an object is promise-like:

var isPromiseLike = function isPromiseLike(obj) {return obj && isFunction(obj.then);};

ngAnimate does this:

var isPromiseLike = function(p) {
    return p && p.then ? true : false;
};

and Angular.js does this:

function isPromiseLike(obj) {
    return obj && isFunction(obj.then);
}

Perhaps they should all be changed to this:

function isPromiseLike(obj) {
    return obj && typeof obj.then === 'function';
}
jbedard commented 8 years ago

There's also another stricter version in $q

aebabis commented 8 years ago

@jbedard Perhaps $q should expose this functionality for other apps to use.

lgalfaso commented 8 years ago

The version at promises-aplus-test-adapter should probably be removed as $q does not use it. I think it is not easy to expose isPromiseLike inside $q and make $q use that implementation without making the code slightly weird, but if someone wants to give it a shoot, then I can review the PR