From 6da06836053be7946b8be727bedfc7e102db68d3 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 31 Oct 2011 10:36:30 -0400 Subject: [PATCH] create empty tail as an invariant --- backbone.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/backbone.js b/backbone.js index 74f2a774..ab2146be 100644 --- a/backbone.js +++ b/backbone.js @@ -74,8 +74,10 @@ bind : function(ev, callback, context) { var calls = this._callbacks || (this._callbacks = {}); var list = calls[ev] || (calls[ev] = {}); - var tail = list.tail || list; - list.tail = tail.next = {callback: callback, context: context}; + var tail = list.tail || (list.tail = list.next = {}); + tail.callback = callback; + tail.context = context; + list.tail = tail.next = {}; return this; }, @@ -83,17 +85,16 @@ // callbacks for the event. If `ev` is null, removes all bound callbacks // for all events. unbind : function(ev, callback) { - var calls, list, node, prev; + var calls, node, prev; if (!ev) { this._callbacks = {}; } else if (calls = this._callbacks) { if (!callback) { calls[ev] = {}; - } else if (list = node = calls[ev]) { + } else if (node = calls[ev]) { while (prev = node, node = node.next) { if (node.callback !== callback) continue; prev.next = node.next; - if (list.tail === node) list.tail = prev; node.context = node.callback = null; break; }