This file contains hidden or 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
//Load the requirejs optimizer | |
var requirejs = require('./path/to/r.js'), | |
//Set up basic config, include config that is | |
//common to all the optimize() calls. | |
basConfig = { | |
baseUrl: './some/path', | |
paths: { | |
//whatever is neded globally. | |
} | |
}; |
This file contains hidden or 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
// Define a module "a" that depends another module called "b". If | |
// that other module also uses this type of boilerplate, then | |
// in the browser, it will create a global .b that is used below. | |
// If you do not want to support the browser global path, then you | |
// can remove the `root` use and the passing `this` as the first arg to | |
// the top function. | |
(function(root, factory) { | |
if (typeof exports === 'object') { |
This file contains hidden or 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
// Basic approach. Does not try to register in | |
// a CommonJS environment since jQuery is not likely | |
// to run in those environments. See next file | |
// if you want to opt in to CommonJS too. | |
(function(factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define(['jquery'], factory); | |
} else { |
This file contains hidden or 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 some/thing.js | |
define('some/thing', ['a', 'some/b'], function (a, b) { | |
return 'value'; | |
}); | |
//YUI loader would apply the return value from the define | |
//as the 'some/thing' property on the YUI instance, | |
//so the above module could be used like so: | |
//in some code that uses YUI: |
This file contains hidden or 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
/** | |
* First, better, "set exports/return" option | |
*/ | |
(function (define) { | |
//The 'id' is optional, but recommended if this is | |
//a popular web library that is used mostly in | |
//non-AMD/Node environments. However, if want | |
//to make an anonymous module, remove the 'id' | |
//below, and remove the id use in the define shim. | |
define('id', function (require) { |
This file contains hidden or 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
/*jslint strict: false, onevar: false, indent: 2 */ | |
/*global require: false, process: false */ | |
var requirejs = require('./jasmine/lib/r.js'); | |
requirejs.config({ | |
nodeRequire: require | |
}); | |
//requirejs(['require', 'jasmine-node', 'jasmine-node/lib/jasmine-node/jasmine-1.0.1', 'sys'], |
This file contains hidden or 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
//Came across this in the es-discuss list, on the "clean scope" thread: | |
https://mail.mozilla.org/pipermail/es-discuss/2011-August/thread.html#16294 | |
//I do not understand what the "null," part buys. | |
//Has to do something with scope(?), but at least in Firebug, | |
//I can see foo inside the string being evaled. | |
var foo = 'foo'; | |
(null,eval)('(function(){console.log(foo);}())'); |
This file contains hidden or 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
//******************************************* | |
// Level 1, basic API, minimum support | |
//******************************************* | |
/* | |
Modules IDs are strings that follow CommonJS | |
module names. | |
*/ | |
//To load code at the top level JS file, | |
//or inside a module to dynamically fetch |
This file contains hidden or 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
/* | |
Define a library called foo that has a parse and render | |
functionality, and a utility function called escape. | |
*/ | |
/** foo.js **/ | |
//If wanting a global, declare it here | |
var foo; | |
//Assemble foo from parts |
This file contains hidden or 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
/* | |
Directory layout | |
app.html | |
scripts | |
- require.js | |
- one.js | |
- two.js | |
- three.js | |
*/ |