Skip to content

Instantly share code, notes, and snippets.

@pcdinh
Forked from bavardage/utils.js
Created December 9, 2009 09:34
Show Gist options
  • Save pcdinh/252367 to your computer and use it in GitHub Desktop.
Save pcdinh/252367 to your computer and use it in GitHub Desktop.
function randomColor() {
var color = (0xffffff * Math.random()).toString(16);
return "#" + color.replace(/\./i,"").slice(0,6);
};
function fallbackFor(arg, fallback) {
return (typeof arg !== 'undefined') ? arg : fallback;
}
function require(arg, name) {
if(typeof arg === 'undefined') {
var fn = functionName(arguments.callee.caller);
throw new SyntaxError(name + " is required in " + fn);
} else {
return arg;
}
}
function functionName(fn) {
var name=/\W*function\s+([\w\$]+)\(/.exec(fn);
if(!name) return 'anonymous function: ' + fn.toString();
return name[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment