[gjs] Lang.bind: Use Function.bind() if we're not currying
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] Lang.bind: Use Function.bind() if we're not currying
- Date: Thu, 30 Jun 2011 19:24:24 +0000 (UTC)
commit 9046d4496ca5d54b34352100fa3a4e8e4461df5a
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Thu Jun 30 15:03:49 2011 -0400
Lang.bind: Use Function.bind() if we're not currying
The standard Function.bind() works, but doesn't support passing
additional arguments.
modules/lang.js | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/modules/lang.js b/modules/lang.js
index 018928e..5642a01 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]