Skip to content

Instantly share code, notes, and snippets.

@storytime
Created April 21, 2014 11:48
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 storytime/11140471 to your computer and use it in GitHub Desktop.
Save storytime/11140471 to your computer and use it in GitHub Desktop.
RequireJS Example
define(function () {
return function (s) {
return s.toUpperCase();
};
});
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<!-- data-main attribute tells require.scripts to load
scripts/main.scripts after require.scripts loads. -->
<script data-main="scripts/main" src="http://requirejs.org/docs/release/2.1.11/comments/require.js"></script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
require(["helper/fk", "helper/values"], function (fk,val) {
//This function is called when scripts/helper/values.js is loaded.
//If values.js calls define(), then this function is not fired until
//util's dependencies have loaded, and the util argument will hold
//the module value for "helper/util".
console.log("from values.js " + val.red)
console.log("from fk.ks " + fk("string"))
});
define (
{
red: "red",
green: "green",
black: "black"
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment