Skip to content

Instantly share code, notes, and snippets.

@tridungpham
Created June 30, 2015 07:40
Show Gist options
  • Save tridungpham/2fd35b99450374c45c5d to your computer and use it in GitHub Desktop.
Save tridungpham/2fd35b99450374c45c5d to your computer and use it in GitHub Desktop.
var asyncModule = function(name) {
return {
controller: function() {
m.request({
method: "GET",
url: name + ".js",
deserialize: function(data) {
return new Function("var module = {};" + data + ";return module").call().exports
}
})
.then(function(module) {
this.controller = new module.controller()
this.view = module.view
}.bind(this))
},
view: function(ctrl) {
return ctrl.view(ctrl.controller)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment