Created
June 15, 2019 16:14
-
-
Save jasontwuk/97605c5367fb61437aca0d4cf831b843 to your computer and use it in GitHub Desktop.
Watch and Code - Beasts 2. Improving runWithDebugger
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 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