Skip to content

Instantly share code, notes, and snippets.

View jrburke's full-sized avatar

James Burke jrburke

View GitHub Profile
We couldn’t find that file to show.
@jrburke
jrburke / gist:641816
Created October 23, 2010 05:01
Aligned injections
define(["some/module1", "foo", "another/module2", "bar"],
function(module, foo, module2, bar) {
module.doSomething();
});
@jrburke
jrburke / onetwothree.js
Created February 3, 2011 00:53
Sample layout for a one two three
/*
Directory layout
app.html
scripts
- require.js
- one.js
- two.js
- three.js
*/
@jrburke
jrburke / oneOutOfMany.js
Created February 7, 2011 08:13
How one piece of functionality could be created out of many files.
/*
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
@jrburke
jrburke / apiexamples.js
Created April 7, 2011 05:50
Description of browser-friendly module APIs: AMD and Loader Plugins
//*******************************************
// 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
@jrburke
jrburke / nulleval.js
Created August 17, 2011 20:58
(null,eval)('')
//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);}())');
@jrburke
jrburke / runTests.js
Created August 22, 2011 21:42
jasmine hacking for use in requirejs on node, not really usable
/*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'],
@jrburke
jrburke / gist:1262861
Created October 4, 2011 21:26
Universal (AMD/Node/plain browser) module
/**
* 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) {
@jrburke
jrburke / gist:1301798
Created October 20, 2011 17:53
AMD in YUI?
//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:
@jrburke
jrburke / basic.js
Created November 7, 2011 07:14
possible jquery plugin boilerplate
// 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 {