Last active
August 29, 2015 14:11
-
-
Save devdays/868f0436179d08ff0c28 to your computer and use it in GitHub Desktop.
Object JavaScript - Define a Module
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
// 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