Skip to content

Instantly share code, notes, and snippets.

@devdays
Last active August 29, 2015 14:11
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 devdays/868f0436179d08ff0c28 to your computer and use it in GitHub Desktop.
Save devdays/868f0436179d08ff0c28 to your computer and use it in GitHub Desktop.
Object JavaScript - Define a Module
// in Scripts/discount.js
define(
// Module ID
'discount',
// no dependencies here, but RequireJS is smart enough to figure that out
// but if you had some, they would go here
// the thing you want to do
function () {
// properties
var pct = 0,
// methods
calculateDiscount = function (level) {
switch (level) {
case 'partner':
pct = 10;
break;
case 'employee':
pct = 27;
break;
default:
pct = 0;
}
return pct;
}
return {
calculateDiscount: calculateDiscount
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment