// Define View Manager to manage view states
window.VM = window.VM || {};

// VM.views hold all references to existing views
VM.views = VM.views || {};

// Close view
VM.closeView = function(name) {
	if (typeof VM.views[name] !== 'undefined') {
		// Cleanup view
		// Remove all of the view's delegated events
		VM.views[name].undelegateEvents();
		// Remove view from the DOM
		VM.views[name].remove();
		// Removes all callbacks on view
		VM.views[name].off();

		if (typeof VM.views[name].close === 'function') {
			VM.views[name].close();
		}
	}
};

// VM.createView always cleans up existing view before
// creating a new one.
// callback function always return a new view instance
VM.createView = function(name, callback) {
    VM.closeView(name);
	VM.views[name] = callback();
	return VM.views[name];
};

// VM.reuseView always returns existing view. Otherwise it
// execute callback function to return new view
// callback function always return a new view instance
VM.reuseView = function(name, callback) {
	if (typeof VM.views[name] !== 'undefined') {
		return VM.views[name];
	}
	
	VM.views[name] = callback();
	return VM.views[name];
};

@@ -155,21 +155,30 @@
 / Close 
+existing 
 view%0A
-
 VM.close
@@ -198,32 +198,33 @@
 on(name) %7B%0A%09if (
+ 
 typeof VM.views%5B
@@ -469,24 +469,25 @@
 f();%0A%0A%09%09if (
+ 
 typeof VM.vi
@@ -738,12 +738,9 @@
 ) %7B%0A
-    
+%09
 VM.c
@@ -1022,16 +1022,17 @@
  %7B%0A%09if (
+ 
 typeof V
@@ -1096,10 +1096,9 @@
 %0A%09%7D%0A
-%09
 %0A
+
 %09VM.
@@ -1127,31 +1127,30 @@
 ();%0A%09return VM.views%5Bname%5D;%0A
+
 %7D;
-%0A

improve readability