Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 11, 2015 00:49
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 philmander/4519568 to your computer and use it in GitHub Desktop.
Save philmander/4519568 to your computer and use it in GitHub Desktop.
// Mixed.js
define(function() {
var Mixed = function(a, b) {
this.a = a;
this.b = b;
};
Mixed.prototype.getA = function() {
return this.a;
};
Mixed.prototype.getB = function() {
return this.b;
};
return Mixed;
});
// ToMix.js
define(function() {
var ToMix = function(x, y) {
this.x = x;
this.y = y;
};
ToMix.prototype.getX = function() {
return this.x;
};
ToMix.prototype.getY = function() {
return this.y;
};
return ToMix;
});
define(function() {
return {
protos: {
mixed: {
module: "Mixed",
args: [ "A", "B" ],
//a list of proto references to mix
mixin: [ "toMix" ]
},
toMix: {
module: "ToMix",
args: [ "X", "Y" ]
}
}
};
});
// Inverted dynamically updates an instance of Mixed
// which effectively looks like this:
var Mixed = function(a, b) {
this.a = a;
this.b = b;
this.__toMix__; //is an instance of ToMix
};
Mixed.prototype.getA = function() {
return this.a;
};
Mixed.prototype.getB = function() {
return this.b;
};
Mixed.prototype.getX = function() {
return this.__toMix__.getX();
};
Mixed.prototype.getY = function() {
return this.__toMix__.getY();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment