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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -