Skip to content

Instantly share code, notes, and snippets.

Created January 4, 2011 04:35
Show Gist options
  • Save anonymous/764403 to your computer and use it in GitHub Desktop.
Save anonymous/764403 to your computer and use it in GitHub Desktop.
is this insane?
Object.prototype._create = function(opts) {
function F() {};
F.prototype = this;
var f = new F();
f._includes();
if (!f.initialize && opts) {
f.initialize = function(opts) {
$.extend(this, opts);
}
}
if(f.initialize) f.initialize(opts)
return f;
};
Object.prototype._includes = function() {
if (this.includes) {
$.each(this.includes, function(index, include) {
extend(f, include);
});
}
}
var Foo = {
hello: function() {
alert("Hello "+ this.name);
}
}
var Bar = {
includes: [Foo]
};
var bar = Bar._create({name:"World"});
bar.hello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment