Skip to content

Instantly share code, notes, and snippets.

@AutoSponge
Last active December 10, 2015 15:29
Show Gist options
  • Save AutoSponge/4454726 to your computer and use it in GitHub Desktop.
Save AutoSponge/4454726 to your computer and use it in GitHub Desktop.
(function (global) {
var Class = {};
var app = {};
function fluent(obj, fn) {
return function () {
fn.apply(obj, arguments);
return obj;
}
}
function instantiate(fn, args, callback) {
return callback(new (fn.bind.apply(fn, [null].concat(args))));
}
function augment(obj, prop, val){
obj[prop] = val;
}
app.get = function (name, args, callback) {
return instantiate(Class[name], args, callback);
};
app.fluent = fluent;
app.add = fluent(app, function (prop, val) {
augment(Class, prop, val);
});
app.proto = fluent(app, function (name, prop, val) {
augment(Class[name].prototype, prop, val);
});
global.app = app;
}(this));
app.add("Person", function (name) {
this.name = name;
}).proto("Person", "say", function () {
console.log(this.name);
}).get("Person", ["Bob"], function (person) {
person.say();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment