The following code is valid in ESLint with Google's style guide with one exception; the closure function Counter
gets a no-unused-vars
error when the script is checked using ESLint.
/**
* Create a counter that is incremented and returned when called
* @return {object} - incrementor function
*/
function Counter() {
var _i = 0;
/**
* increment counter
* @return {int} - The incremented integer
*/
function _incrementor() {
_i++;
return _i;
}
_incrementor.incr = function() {
this.call();
return _incrementor;
};
_incrementor.val = function(val) {
if (!arguments.length) { return _i; }
_i = val;
return _incrementor;
};
return _incrementor;
}
I would like to have this function (or one structure the same way) as a standalone script that I can include in my HTML and then call from a different script like so:
var count = Counter()
.val(5);
count.incr()
console.log(count.val()) // prints => 6
I have tried including /* exported Counter */
at the top of the script but the error persists. How do I silence/fix this error?