From 238d7c86f4518331cf7563d6baf622401e07a59c Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Fri, 4 May 2012 23:09:04 -0700 Subject: use proxy instead of self --- lib/completion.js | 9 ++++----- lib/utils.js | 5 ++++- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/completion.js b/lib/completion.js index 7e4bcf57..14c2dbe4 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -50,8 +50,7 @@ var completion = (function() { }, filter: function(query, callback) { - var self = this; - var handler = function(results) { callback(self.processResults(query, results)); } + var handler = function(results) { callback(this.processResults(query, results)); }.proxy(this); // are the results ready? if (this.completions !== null) { @@ -61,9 +60,9 @@ var completion = (function() { // no: register the handler as a callback this.resultsReady = function(results) { handler(results); - self.resultsReady = self.fallbackReadyCallback; - self.resultsReady(results); - } + this.resultsReady = this.fallbackReadyCallback; + this.resultsReady(results); + }.proxy(this); } } }); diff --git a/lib/utils.js b/lib/utils.js index 3a355d7b..d6b7bb93 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -160,7 +160,10 @@ var utils = { }; /* Execute a function with the given value for "this". Equivalent to jQuery.proxy(). */ -Function.prototype.proxy = function(fn, self) { return function() { fn.apply(self, arguments); }; }; +Function.prototype.proxy = function(self) { + var fn = this; + return function() { return fn.apply(self, arguments); }; +}; /* -- cgit v1.2.3