Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 12, 2014 00:49
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/6fe0f69be6adab917eb1 to your computer and use it in GitHub Desktop.
Save devdays/6fe0f69be6adab917eb1 to your computer and use it in GitHub Desktop.
Object JavaScript - Define module has a dependency on another module
// in project.js
define(
// an optional module ID
'product',
// this module needs the discount.js as a dependency
['discount'],
// the requireJS loader provides discount as a parameter.
// if you have more than one in the array above, then you get
// them in the same order for your function.
function (discount) {
// properties
var productName = '';
var price = 1;
var discountedPrice = function (level) {
return price - (price * discount.calculatDiscount(level));
};
return {
productName: productName,
price: price,
discountedPrice: discountedPrice
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment