Skip to content

Instantly share code, notes, and snippets.

@BruceHubbard
Created July 19, 2011 15:35
Show Gist options
  • Save BruceHubbard/1092805 to your computer and use it in GitHub Desktop.
Save BruceHubbard/1092805 to your computer and use it in GitHub Desktop.
RequireJS Example
define(
// template dependency
[
'app/text!app/views/templates/myMustacheTemplate.html',
'Scripts/mustache/mustache',
'Scripts/jquery',
'Scripts/jquery-ui-1.8.13.min',
'app/services/myServiceFile'
],
/* This runs once dependencies are loaded */
function (myTpl) {
//you can now use jquery, jqueryUI, mustache, myService (app level service js file) and
// the myTpl variable will contain the text contents of myMustacheTemplate.html so you run
// run mustache on it
//This means all of your dependencies are declared here locally instead of outside the scope of
// this js file with the hope they'll get loaded elsewhere. Require also allows you to create
// site wide dependencies so you don't have to include common libs like JQuery/JQueryUI in every js
// file.
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment