Skip to content

Instantly share code, notes, and snippets.

@meeDamian
Created June 27, 2013 09:41
Show Gist options
  • Save meeDamian/5875254 to your computer and use it in GitHub Desktop.
Save meeDamian/5875254 to your computer and use it in GitHub Desktop.
// dodajesz gdzieś raz do bibliotek
function goforit() {
if( active ) {
var args = Array.prototype.slice.call(arguments, 0);
(args.shift()).apply(null, args);
}
return active;
}
// funkcje do uruchomienia
function fun1( a, b ) {
console.log("f1", a, b, a+b);
}
function fun2( c, d ) {
console.log("f2", Math.pow(c,d));
}
// wylosuj stan: true|false
var active = !!Math.round(Math.random());
// stare podejście:
(function oldWay() {
if( active ) fun1( 7, 5 );
// do sth else
if( active ) fun2( 4, 3 );
})();
// nowe podejście:
(function newWay() {
goforit( fun1, 7, 5 );
// do sth else
goforit( fun2, 4, 3 );
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment