jslint - Get warning when passing too few arguments to a javascript function -
is there tool can me detect when javascript function being passed few arguments? far can tell, neither jslint nor jshint provides feature.
just make clear, if write:
some_method = function(x,y) { // ..do stuff } some_method(2);
i warned, might have pass in argument.
you can't that, parameters optional , can pass indefinite amount of parameters parameterless function (through arguments array).
but can use arguments array test own methods manually. have add each method individually, since can't reflect amount of arguments in method signature. specific case use:
function test(x, y) { if (arguments.length !== 2) { console.log('error, invalid amount of args'); } } test(1); // trigger console.log , type error.
if need parameter checking use typescript, parameters required default.
Comments
Post a Comment