JSLint impled global

U

Une Bévue

JSLint founds errors :
Error:
Implied global: findTextInTag 6, hash 3, keysAry 2

"findTextInTag" is an external function to the calling one

hash and keysAry are (supposed to be?) global variables defined like
that :

var keysAry = new Array();
keysAry = [ "name", "address", "tel", "email", "url", "im", "note" ];

var hash = new Array();
// "name", "address", "tel", "email", "url", "im",
"note"
hash[ "all" ] = [ true, true, true, true, true, true,
true ];
[...]
hash[ "note" ] = [ false, false, false, false, false, false,
true ];


the script is working however i wonder about those "errors", in other
word how to make the variables "hash" and "keysAry" explicitely globals
?

also, the function "findTextInTag" is called (always) from another one
"findTextInWhat", there are defined like that :

function findTextInWhat( person, txt, what ) {
// the content //
}
function findTextInTag( person, txt, tag ) {
// the content //
}

more precisely why this is an error calling "findTextInTag" from inside
"findTextInWhat" ?

what means "implied global" here ? I'd suppose implied is opposed to
explicit ?
 
T

Tom de Neef

"Une Bév said:
JSLint founds errors :
Error:
Implied global: findTextInTag 6, hash 3, keysAry 2
the script is working however i wonder about those "errors", in other
word how to make the variables "hash" and "keysAry" explicitely globals
?
what means "implied global" here ? I'd suppose implied is opposed to
explicit ?
--

There is some documentation with JSlint at http://www.jslint.com/lint.html
It states:
JavaScript's biggest problem is its dependence on global variables,
particularly implied global variables. If a variable is not explicitly
declared (usually with the var statement), then JavaScript assumes that the
variable was global. This can mask misspelled names and other problems.

JSLint expects that all variables and functions are declared before they are
used or invoked. This allows it to detect implied global variables. It is
also good practice because it makes programs easier to read.

Tom
 
U

Une Bévue

Tom de Neef said:
JSLint expects that all variables and functions are declared before they are
used or invoked. This allows it to detect implied global variables. It is
also good practice because it makes programs easier to read.

OK, thanks a lot, in fact i didn't cut'n paste all of my code, that's
the reason way JSLint didn't see some variables as being explicitely
global...

I thought i had missunderstood something...
 
T

Thomas 'PointedEars' Lahn

*Implicit* is opposed to explicit. Implied means "follows from", as in a
logical conclusion.
There is some documentation with JSlint at http://www.jslint.com/lint.html
It states:
JavaScript's biggest problem is its dependence on global variables,
particularly implied global variables. If a variable is not explicitly
declared (usually with the var statement), then JavaScript assumes that the
variable was global.

But that is utter nonsense.

Whenever a simple assignment to an undeclared identifier takes place, an
object in the Scope Chain that has this property takes responsibility. If
there is no such object, the Global Object is added a property.

Whenever an identifier is used, that was not declared before, in another
way, the Scope Chain is followed until an object is found that has a
property with that identifier as name. If there is no such object, a
ReferenceError exception is thrown.

While global variables are also properties of the Global Object, they differ
from non-variable properties in the regard that they have the DontDelete
attribute.
This can mask misspelled names and other problems.

Bad causes can have bad effects.
JSLint expects that all variables and functions are declared before they are
used or invoked. This allows it to detect implied global variables. It is
also good practice because it makes programs easier to read.

What JSLint detects are _not_ "implied global( variable)s", despite its
saying so. I would have expected the author to know better.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top