diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2011-06-30 15:03:49 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2011-06-30 15:24:51 -0400 |
commit | 9046d4496ca5d54b34352100fa3a4e8e4461df5a (patch) | |
tree | 9bd0e835d68a0adab8ce54462e90d705abe25ff7 /modules | |
parent | f539364e5d7083b4ac0d16c3ac7cd5959fca496b (diff) | |
download | gjs-9046d4496ca5d54b34352100fa3a4e8e4461df5a.tar.gz |
Lang.bind: Use Function.bind() if we're not currying
The standard Function.bind() works, but doesn't support passing
additional arguments.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/lang.js | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/modules/lang.js b/modules/lang.js index 018928e3..5642a012 100644 --- a/modules/lang.js +++ b/modules/lang.js @@ -89,9 +89,6 @@ function removeNullProperties(obj) { * @type: function */ function bind(obj, callback) { - let me = obj; - let bindArguments = Array.prototype.slice.call(arguments, 2); - if (typeof(obj) != 'object') { throw new Error( "first argument to Lang.bind() must be an object, not " + @@ -104,6 +101,12 @@ function bind(obj, callback) { typeof(callback)); } + if (callback.bind && arguments.length == 2) // ECMAScript 5 (but only if not passing any bindArguments) + return callback.bind(obj); + + let me = obj; + let bindArguments = Array.prototype.slice.call(arguments, 2); + return function() { let args = Array.prototype.slice.call(arguments); args = args.concat(bindArguments); |