Skip to content

Instantly share code, notes, and snippets.

@piercus
Last active December 11, 2015 10:58
Show Gist options
  • Save piercus/4590077 to your computer and use it in GitHub Desktop.
Save piercus/4590077 to your computer and use it in GitHub Desktop.
Script to use sand.define's modules with requirejs
if (typeof(define) === "undefined"){
console.log("[ERROR] require.js is not defined");
}
if (typeof(sand) !== "undefined"){
console.log("[ERROR] sand is already defined");
}
var sand;
(function(){
Array.prototype.last = String.prototype.last = function() {
return this[this.length - 1];
};
var parse = function(name){return name.split('/').last()};
sand = {
define : function(name, requires, fn, options){
if (typeof(requires) === 'function') {
fn = requires;
requires = [];
} else if (typeof(requires) === 'undefined') requires = [];
var amdFn = function(){
var r = {};
for (var i = 0; i < arguments.length; i++){
var alias = requires[i].split("->")[1] || parse(requires[i]);
r[alias] = arguments[i];
}
return fn(r);
}
define(name, requires, amdFn);
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment