Created
March 23, 2009 01:03
-
-
Save quackingduck/83359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var viewController = (function(){ | |
var baseClass = Class({ | |
initialize: function(element) { | |
this.element = $(element); | |
} | |
}); | |
var controllers = {}; | |
// probably insane | |
function setSelf(methods) { | |
var hsh = $H(methods); | |
hsh.each(function(body,name,hash) { | |
if ($type(body) == 'function') { | |
var f; | |
var newBody = "f=" + body.toString().replace('{',"{var self = this;"); | |
hash.set(name,eval(newBody)); | |
} | |
}); | |
return hsh.getClean(); | |
} | |
function define(controllerName, methods) { | |
methods = setSelf(methods); | |
methods.Extends = baseClass; | |
var viewController = new Class(methods); | |
controllers[controllerName] = viewController; | |
return viewController; | |
} | |
function instance(controllerName,element) { | |
return new controllers[controllerName](element || controllerName); | |
} | |
return { define: define, instance: instance } | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment