Skip to content

Instantly share code, notes, and snippets.

@kriszyp
Forked from iaincarsberg/output.txt
Created October 6, 2011 17:17
Show Gist options
  • Save kriszyp/1267999 to your computer and use it in GitHub Desktop.
Save kriszyp/1267999 to your computer and use it in GitHub Desktop.
RequireJS - Compose.js - Chaining Multiple Constructors
Animal - this {}
Animal - debug: [ muppet , bert ]
Hello, my name is bert and I am a muppet
returned: { species: 'muppet', name: 'bert' }
****************************************
Muppet - this {}
Muppet - debug: [ ernie ]
Animal - this {}
Animal - debug: [ muppet , ernie ]
Hello, my name is ernie and I am a muppet
returned: { species: 'muppet', name: 'ernie', whom: [Function] }
****************************************
Muppet - this {}
Muppet - debug: [ undefined ]
Animal - this {}
Animal - debug: [ muppet , undefined ]
Hello, my name is undefined and I am a muppet
returned: { species: 'muppet',
name: undefined,
whom: [Function] }
/*global window console*/
(function (require, undefined) {
require(
[
'./lib/compose/compose'
],
function (
Compose
) {
var Animal = Compose(
function (species, name) {
this.init.apply(this, arguments);
},
{
init: function (species, name) {
console.log('Animal - this', this);
console.log('Animal - debug: [', species, ',', name, ']');
this.species = species;
this.name = name;
},
whom: function () {
console.log(
'Hello, my name is ' + this.name +
' and I am a ' + this.species
);
return this;
}
}
);
var Muppet = Compose(Animal,
{
init: function (name) {
this.species = "muppet";
this.name = name;
},
}
);
console.log(
'returned:', new Animal('muppet', 'bert').whom()
);
console.log('****************************************');
console.log(
'returned:', new Muppet('ernie').whom()
);
console.log('****************************************');
console.log(
'returned:', new Muppet().whom()
);
}
);
}(typeof window === 'undefined' ? require('./lib/r') : require));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment