Skip to content

Instantly share code, notes, and snippets.

@iaincarsberg
Created October 4, 2011 10:58
Show Gist options
  • Save iaincarsberg/1261352 to your computer and use it in GitHub Desktop.
Save iaincarsberg/1261352 to your computer and use it in GitHub Desktop.
RequireJS - Compose.js - Utility/Helper functions
/*global require*/
require('whom', function (Whom) {
if (Whom.allOver18(
new Whom('Iain', 27),
new Whom('Bob', 53),
new Whom('Rob', 19)
)) {
console.log('Drink!');
} else {
console.log('Banned');
}
if (Whom.isIain(new Whom('Iain', 27))) {
console.log('Hello, Iain');
} else {
console.log('Hello, somebody who isn't Iain');
}
});
/*global define*/
define(
[
'compose'
],
function (
Compose
) {
var Whom = Compose(
function (name, age) {
this.name = name;
this.age = age;
},
{
/**
* Used to expose the x coordinate
* @param void
* @return double Containing the x value
*/
whom: function () {
return [
this.name,
'is',
this.age,
'years of age.'
].join(' ');
}
}
);
Whom.isIain = function (who) {
if (who.name === 'Iain') {
return true;
}
return false;
}
Whom.allOver18 = function () {
for(var i = 0; i < arguments.length; i++) {
if (arguments[i].age === undefined ||
arguments[i].age < 18
) {
return false;
}
}
return true;
}
return Whom;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment