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(["some/module1", "foo", "another/module2", "bar"], | |
function(module, foo, module2, bar) { | |
module.doSomething(); | |
}); |
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 | |
*/ |
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
//******************************************* | |
// 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
//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
/*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
/** | |
* 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
//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
// 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 { |
OlderNewer