Pass context to .forEach instead of closure
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Has a slight performance improvement closes #2347
authored by lemmy · committed by Douglas Christopher Wilson · parent e9539fc · Browse files · 3 files·+19 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+19 added−24 removed
- other:+19 added−24 removed
Provenance
- Commit
dfa7ee4- Tree
c4f1572- Author
lemmy <lemmy@yandex-team.ru>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
e9539fc
3 files changed+19 added−24 removed
modified:lib/router/index.js+3 added-4 removed
407 unmodified lines408 409 proto.use = function use(fn) {410 var offset = 0;411 var path = '/';412- var self = this;412 413 // default path to '/'414 // disambiguate router.use([fn])415 if (typeof fn !== 'function') {24 unmodified lines440 // add the middleware441 debug('use %s %s', path, fn.name || '<anonymous>');442 443 var layer = new Layer(path, {445- sensitive: self.caseSensitive,444+ sensitive: this.caseSensitive,445 strict: false,446 end: false447 }, fn);448 449 layer.route = undefined;450 452- self.stack.push(layer);453- });451+ this.stack.push(layer);452+ }, this);453 454 return this;455 };456 119 unmodified linesmodified:lib/router/route.js+9 added-11 removed
129 unmodified linesExpand all1301311321331341341351361373 unmodified lines141142143144146147148145146147148150149150151152153155154155156157158159160161162165163164165166167170171172173168169170171172173129 unmodified linesExpand all * @api public */
Route.prototype.all = function(){ var self = this; var callbacks = utils.flatten([].slice.call(arguments)); callbacks.forEach(function(fn) { if (typeof fn !== 'function') { var type = {}.toString.call(fn);3 unmodified lines
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) { if (typeof fn !== 'function') { var type = {}.toString.call(fn); var msg = 'Route.' + method + '() requires callback functions but got a ' + type; 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; };});modified:lib/application.js+7 added-9 removed
152 unmodified lines153 154 app.use = function use(fn) {155 var offset = 0;156 var path = '/';157- var self = this;157 158 // default path to '/'159 // disambiguate app.use([fn])160 if (typeof fn !== 'function') {27 unmodified lines188 }189 190 debug('.use app under %s', path);191 fn.mountpath = path;193- fn.parent = self;192+ fn.parent = this;193 194 // restore .app property on req and res195 router.use(path, function mounted_app(req, res, next) {196 var orig = req.app;4 unmodified lines201 });202 });203 204 // mounted an app206- fn.emit('mount', self);207- });205+ fn.emit('mount', this);206+ }, this);207 208 return this;209 };210 65 unmodified lines276 * @api public277 */278 279 app.param = function(name, fn){281- var self = this;282- self.lazyrouter();280+ this.lazyrouter();281 282 if (Array.isArray(name)) {283 name.forEach(function(key) {286- self.param(key, fn);287- });284+ this.param(key, fn);285+ }, this);286 return this;287 }288 291- self._router.param(name, fn);289+ this._router.param(name, fn);290 return this;291 };292 293 /**275 unmodified lines