Created
October 4, 2011 10:58
-
-
Save iaincarsberg/1261352 to your computer and use it in GitHub Desktop.
RequireJS - Compose.js - Utility/Helper functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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'); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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