Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quackingduck/83359 to your computer and use it in GitHub Desktop.
Save quackingduck/83359 to your computer and use it in GitHub Desktop.
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