From 1a2d3f277d243f1c069a20f7b1e3ac1fc2165b67 Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Thu, 7 Nov 2013 15:13:28 +0200 Subject: [PATCH] Improve events performance in some cases by 20x. Things like [Chaplin](http://chaplinjs.org) are using advanced memory management heavily. This includes unbinding of all events too. Events are getting unbound all the time. When other objects may still try to trigger events, this will increase performance by 20x. Initially taken from [my Backbone optional-dependencies fork](http://exosjs.com). Proof of 20x speed: http://jsperf.com/exoskeleton-events-vs-backbone-events --- backbone.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backbone.js b/backbone.js index 12170e2f8..dcfd89d18 100644 --- a/backbone.js +++ b/backbone.js @@ -115,7 +115,7 @@ var retain, ev, events, names, i, l, j, k; if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this; if (!name && !callback && !context) { - this._events = {}; + this._events = void 0; return this; } names = name ? [name] : _.keys(this._events);