jslint - In Javascript, under what conditions is it appropriate to only use `this` in constructor functions? -
i found an interesting line of code in jshint's config options.
the comment associated option reads tolerate using in non-constructor function.
i confused. misunderstanding config option?
aren't there lot of cases want use this
in non-constructor function? when ever want warned it?
this options used tell jshint function invoked valid this
parameter.
for example:
function myrandomfunction() { alert(this.something); } myrandomfunction.call(someobject);
if strict mode on, jshint warn myrandomfunction
shouldn't using this
, since doesn't constructor or member function.
if know called this
(eg, callback), can add /*jshint validthis: true */
suppress warning.
Comments
Post a Comment