-
-
Save pcdinh/252367 to your computer and use it in GitHub Desktop.
This file contains 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
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