Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fix jslint error 'Don't make functions within a loop.'?
    primarykey
    data
    text
    <p>I am working on making all of our JS code pass through jslint, sometimes with a lot of tweaking with the options to get legacy code pass for now on with the intention to fix it properly later.</p> <p>There is one thing that jslint complains about that I do not have a workround for. That is when using constructs like this, we get the error 'Don't make functions within a loop.'</p> <pre><code>for (prop in newObject) { // Check if we're overwriting an existing function if (typeof newObject[prop] === "function" &amp;&amp; typeof _super[prop] === "function" &amp;&amp; fnTest.test(newObject[prop])) { prototype[prop] = (function(name, func) { return function() { var result, old_super; old_super = this._super; this._super = _super[name]; result = func.apply(this, arguments); this._super = old_super; return result; }; })(prop, newObject[prop]); } } </code></pre> <p>This loop is part of a JS implementation of classical inheritance where classes that extend existing classes retain the super property of the extended class when invoking a member of the extended class. Just to clarify, the implementation above is inspired by this <a href="http://ejohn.org/blog/simple-javascript-inheritance/" rel="noreferrer">blog post</a> by John Resig.</p> <p>But we also have other instances of functions created within a loop.</p> <p>The only workaround so far is to exclude these JS files from jslint, but we would like to use jslint for code validation and syntax checking as part of our continuous integration and build workflow.</p> <p>Is there a better way to implement functionality like this or is there a way to tweak code like this through jslint?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload