Skip to content

Instantly share code, notes, and snippets.

@mde
Created June 2, 2011 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/1005311 to your computer and use it in GitHub Desktop.
Save mde/1005311 to your computer and use it in GitHub Desktop.
JS inheritance stuff
var MyThing = function () {
this.a = function () {
};
this.b = [];
this.c = 'foo';
};
MyThing.prototype = new (function () {
var MY_SETTING = 2112;
var _myPrivateFunc = function () {
};
this.qux = [];
this.foo = function () {
_myPrivateFunction.apply(this);
(function () {
}).apply(this, arguments);
};
this.bar = function () {};
})();
MyMixin = new (function () {
this.zoobie = 2;
this.frang = false;
})();
var foo = new MyThing()
, bar = new MyThing();
for (var p in MyMixin) {
foo[p] = MyMixin[p];
}
foo.qux.push(1);
bar.qux => ?
foo.qux = 'howdy';
bar.qux => ?
delete foo.qux;
foo.qux => ?
bar.qux => ?
foo.foo();
function foo () {}
var foo = function () {};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment