Skip to content

Instantly share code, notes, and snippets.

@jasontwuk
Created June 15, 2019 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasontwuk/97605c5367fb61437aca0d4cf831b843 to your computer and use it in GitHub Desktop.
Save jasontwuk/97605c5367fb61437aca0d4cf831b843 to your computer and use it in GitHub Desktop.
Watch and Code - Beasts 2. Improving runWithDebugger
function runWithDebugger(callback, array){
debugger;
// when has second argument
if(arguments.length > 1){
// when second argument's type is array
if(Array.isArray(array)){
callback.apply(null, array);
// when second argument's type is not array
} else {
try {
throw new TypeError('The second argument must be an array.');
} catch(e) {
console.error(e.stack);
}
}
// when no second argument
} else {
callback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment