diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-07-11 12:41:20 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2015-07-11 12:41:20 -0400 |
commit | 68b4f5b4b7dfb6634f505d79ceb38e517d89ca68 (patch) | |
tree | c0ea8ebd67597d40d0ffb5c5f64fe1a865bfee1a /lib | |
parent | 7457aa2b6cb6a27af81752f82dbfbdeae9ae8575 (diff) | |
download | async-68b4f5b4b7dfb6634f505d79ceb38e517d89ca68.tar.gz |
Stricter type checking
Diffstat (limited to 'lib')
-rw-r--r-- | lib/async.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/async.js b/lib/async.js index f3cfb80..d5dfce5 100644 --- a/lib/async.js +++ b/lib/async.js @@ -62,6 +62,12 @@ return _toString.call(obj) === '[object Array]'; }; + // Ported from underscore.js isObject + var _isObject = function(obj) { + var type = typeof obj; + return type === 'function' || type === 'object' && !!obj; + }; + function _isArrayLike(arr) { return _isArray(arr) || ( // has a positive integer length property @@ -1013,7 +1019,7 @@ function _console_fn(name) { return _restParam(function (fn, args) { fn.apply(null, args.concat([_restParam(function (err, args) { - if (typeof console !== 'undefined') { + if (typeof console === 'object') { if (err) { if (console.error) { console.error(err); @@ -1186,7 +1192,7 @@ return callback(e); } // if result is Promise object - if (typeof result !== 'undefined' && typeof result.then === "function") { + if (_isObject(result) && typeof result.then === "function") { result.then(function(value) { callback(null, value); }).catch(function(err) { @@ -1199,11 +1205,11 @@ }; // Node.js - if (typeof module !== 'undefined' && module.exports) { + if (typeof module === 'object' && module.exports) { module.exports = async; } // AMD / RequireJS - else if (typeof define !== 'undefined' && define.amd) { + else if (typeof define === 'function' && define.amd) { define([], function () { return async; }); |