Writing a JavaScript Public Library? Validate Your Arguments
How many times have seen an obscure JavaScript error when using one 3rd party library or another? More likely than not, you’ve come across a message like:
TypeError: Cannot call method 'someMethod' of undefined
Your browser or the Node.js interpreter will tell you in which file and on which line that error has occurred. Then, you’ll start a very mundane task of examining the code of a 3rd party library, if it’s has not been minimised, of course. Eventually, you will find out that you have forgotten to provide one of the arguments required by a function. You may even see a more obscure error.
mikeborozdin.com