Created
January 26, 2018 23:15
-
-
Save yesmar/06c81c26435f3d358d238ab60d89a07b to your computer and use it in GitHub Desktop.
Run code through the Chrome debugger with an optional args parameter
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() { | |
'use strict'; | |
function runWithDebugger(f, args) { | |
if (typeof f !== 'function') { throw 'f must be a function' } | |
// The apply() method treats unspecified args or null or undefined args as 'no args'. | |
if (args === undefined || typeof args === 'object' && (args === null || Array.isArray(args))) { | |
debugger; | |
f.apply(null, args); | |
} else { | |
throw 'args must be an array, null or undefined'; | |
} | |
} | |
window.runWithDebugger = runWithDebugger; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
args
is not specified it is treated asundefined
, which tells theapply
method that there are no arguments. (See Function.prototype.apply() for details.)Test cases
Additional test cases