Throw an error if Backbone.history.start is called twice.

This commit is contained in:
Jeremy Ashkenas
2011-02-07 10:28:13 -05:00
parent 1944234c74
commit f1e0f6b5c1

View File

@@ -709,6 +709,9 @@
// Cached regex for cleaning hashes.
var hashStrip = /^#*/;
// Has the history handling already been started?
var historyStarted = false;
// Set up all inheritable **Backbone.History** properties and methods.
_.extend(Backbone.History.prototype, {
@@ -724,6 +727,7 @@
// Start the hash change handling, returning `true` if the current URL matches
// an existing route, and `false` otherwise.
start : function() {
if (historyStarted) throw new Error("Backbone.history has already been started.");
var docMode = document.documentMode;
var oldIE = ($.browser.msie && (!docMode || docMode <= 7));
if (oldIE) {
@@ -734,6 +738,7 @@
} else {
setInterval(this.checkUrl, this.interval);
}
historyStarted = true;
return this.loadUrl();
},