Skip to content

Instantly share code, notes, and snippets.

@skippy
Created July 5, 2011 06:46
Show Gist options
  • Save skippy/1064363 to your computer and use it in GitHub Desktop.
Save skippy/1064363 to your computer and use it in GitHub Desktop.
require within own namespace
window.myApp = window.myApp || {};
(function( myApp, undefined ) {
var require, define;
(function () {
//wrap require.js in our namespace!
var version = "0.24.0".........
}());
myApp.require = require;
myApp.define = define;
}( window.myApp ));
(function( myApp, undefined ) {
var setupOptions = {};
var coreLibraries = [];
myApp.require(["vendor/jquery.1.6.2"], function($) {
// right here, '$' is null (not undefined)
});
}( window.myApp ));
<!DOCTYPE html>
<html>
<head>
<script src="http://requirejs.org/docs/release/0.24.0/minified/require.js"></script>
<script>
require(["javascripts/vendor/jquery.1.6.2"], function($) {
// $ == null; how odd!
console.log("TEST: ", $)
});
</script>
</head>
<body>
<h1>test</h1>
<p>Look at source or inspect the DOM to see how it works.</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment