Skip to content

Instantly share code, notes, and snippets.

@rkh
Created May 24, 2010 16:20
Show Gist options
  • Save rkh/412083 to your computer and use it in GitHub Desktop.
Save rkh/412083 to your computer and use it in GitHub Desktop.
var sys = require("sys");
var extend = function extend (another) {
var prototype = this.__proto__;
this.__proto__ = another;
another.__proto__ = prototype;
return this;
};
Object.defineProperty(Object.prototype, "extend", {value: extend });
var Model = new Function();
Model.prototype = {
saySomething: function() {
sys.puts("Yes, I am a model!");
}
}
var NotModel = new Function();
NotModel.prototype = {
saySomething: function() {
sys.puts("No, I am not a model!");
}
}
var a = new Model();
var b = new NotModel();
sys.puts("Before extending:");
sys.print("a: "); a.saySomething(); // Yes, I am a model!
sys.print("b: "); b.saySomething(); // No, I am not a model!
var SomeMixin = {};
a.extend(SomeMixin);
b.extend(SomeMixin);
sys.puts("After extending:");
sys.print("a: "); a.saySomething(); // No, I am not a model!
sys.print("b: "); b.saySomething(); // No, I am not a model!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment