angularjs - Unused 'x' in function arguments, but 'x' is needed - JSLint error -
i'm analyzing angularjs code jslint.
many times, have function have multiple argumets, eg:
$rootscope.$on('$statechangesuccess', function (ev, tostate, toparams, fromstate, fromparams) { // code uses tostate, toparams, fromstate, fromparams // touch use ev }) and many times need specify arguments, because use last arguments.
as result other arguments not used, still needed. , jslint throws errors, eg:
unused 'ev'.......
is there way fix it?
sure! can use jslint directive:
/*jslint unparam:true, sloppy:true, white:true, devel:true */ /*global $rootscope*/ $rootscope.$on('$statechangesuccess', function (ev, tostate, toparams, fromstate, fromparams) { // i'm putting in line jslint doesn't complain empty block // , can mimic described situation. console.log(tostate, toparams, fromstate, fromparams); }); in case, unparam:true 1 fixes specific issue. (devel allows console use , few other objects. white allows whitespace, , sloppy allows skip "use strict";. last 2 personal preferences.)
if want turn off single function (or subset of code), can turn unparam off , on this:
/*jslint sloppy:true, white:true, devel:true */ /*global $rootscope*/ /*jslint unparam:true */ $rootscope.$on('$statechangesuccess', function (ev, tostate, toparams, fromstate, fromparams) { console.log(tostate, toparams, fromstate, fromparams); }); /*jslint unparam:false */ unparam useful these kinds of situations. event handler function signatures 1 in 3rd party libraries difficult use without option.
Comments
Post a Comment