From 959f1b430ddbd1d946333e9a820f7ae058078c73 Mon Sep 17 00:00:00 2001 From: lemmy Date: Sat, 6 Sep 2014 21:35:17 +0400 Subject: [PATCH] Remove unnecessary referencing to `this` --- lib/application.js | 16 +++++++--------- lib/response.js | 3 +-- lib/router/index.js | 7 +++---- lib/router/route.js | 20 +++++++++----------- 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/application.js b/lib/application.js index 2214bf6c1f3..ea80196255d 100644 --- a/lib/application.js +++ b/lib/application.js @@ -154,7 +154,6 @@ app.handle = function(req, res, done) { app.use = function use(fn) { var offset = 0; var path = '/'; - var self = this; // default path to '/' if (typeof fn !== 'function') { @@ -180,7 +179,7 @@ app.use = function use(fn) { debug('.use app under %s', path); fn.mountpath = path; - fn.parent = self; + fn.parent = this; // restore .app property on req and res router.use(path, function mounted_app(req, res, next) { @@ -193,8 +192,8 @@ app.use = function use(fn) { }); // mounted an app - fn.emit('mount', self); - }); + fn.emit('mount', this); + }, this); return this; }; @@ -268,17 +267,16 @@ app.engine = function(ext, fn){ */ app.param = function(name, fn){ - var self = this; - self.lazyrouter(); + this.lazyrouter(); if (Array.isArray(name)) { name.forEach(function(key) { - self.param(key, fn); - }); + this.param(key, fn); + }, this); return this; } - self._router.param(name, fn); + this._router.param(name, fn); return this; }; diff --git a/lib/response.js b/lib/response.js index e929291da39..9ac872d8d0a 100644 --- a/lib/response.js +++ b/lib/response.js @@ -463,8 +463,7 @@ res.sendFile = function sendFile(path, options, fn) { res.sendfile = function(path, options, fn){ options = options || {}; - var self = this; - var req = self.req; + var req = this.req; var next = this.req.next; var done; diff --git a/lib/router/index.js b/lib/router/index.js index 4e63eb1060f..8a822e3eff1 100644 --- a/lib/router/index.js +++ b/lib/router/index.js @@ -402,7 +402,6 @@ proto.process_params = function(layer, called, req, res, done) { proto.use = function use(fn) { var offset = 0; var path = '/'; - var self = this; // default path to '/' if (typeof fn !== 'function') { @@ -427,15 +426,15 @@ proto.use = function use(fn) { debug('use %s %s', path, fn.name || ''); var layer = new Layer(path, { - sensitive: self.caseSensitive, + sensitive: this.caseSensitive, strict: false, end: false }, fn); layer.route = undefined; - self.stack.push(layer); - }); + this.stack.push(layer); + }, this); return this; }; diff --git a/lib/router/route.js b/lib/router/route.js index 6b39211921a..903d1a5e218 100644 --- a/lib/router/route.js +++ b/lib/router/route.js @@ -131,7 +131,6 @@ Route.prototype.dispatch = function(req, res, done){ */ Route.prototype.all = function(){ - var self = this; var callbacks = utils.flatten([].slice.call(arguments)); callbacks.forEach(function(fn) { if (typeof fn !== 'function') { @@ -143,16 +142,15 @@ Route.prototype.all = function(){ var layer = Layer('/', {}, fn); layer.method = undefined; - self.methods._all = true; - self.stack.push(layer); - }); + this.methods._all = true; + this.stack.push(layer); + }, this); - return self; + return this; }; methods.forEach(function(method){ Route.prototype[method] = function(){ - var self = this; var callbacks = utils.flatten([].slice.call(arguments)); callbacks.forEach(function(fn) { @@ -162,14 +160,14 @@ methods.forEach(function(method){ throw new Error(msg); } - debug('%s %s', method, self.path); + debug('%s %s', method, this.path); var layer = Layer('/', {}, fn); layer.method = method; - self.methods[method] = true; - self.stack.push(layer); - }); - return self; + this.methods[method] = true; + this.stack.push(layer); + }, this); + return this; }; });