HighDots Forums  

JSLint impled global

Javascript JavaScript language (comp.lang.javascript)


Discuss JSLint impled global in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Une Bévue
 
Posts: n/a

Default JSLint impled global - 03-20-2008 , 05:22 PM






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 ?
--
Une Bévue

Reply With Quote
  #2  
Old   
Tom de Neef
 
Posts: n/a

Default Re: JSLint impled global - 03-20-2008 , 06:09 PM






""Une Bév" wrote:
Quote:
JSLint founds errors :
Error:
Implied global: findTextInTag 6, hash 3, keysAry 2

snip

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

snip

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




Reply With Quote
  #3  
Old   
Une Bévue
 
Posts: n/a

Default Re: JSLint impled global - 03-21-2008 , 03:58 AM



Tom de Neef <tdeneef (AT) qolor (DOT) nl> wrote:

Quote:
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...
--
Une Bévue


Reply With Quote
  #4  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: JSLint impled global - 03-21-2008 , 01:17 PM



Tom de Neef wrote:
Quote:
""Une Bév" wrote:
JSLint founds errors :
Error:
Implied global: findTextInTag 6, hash 3, keysAry 2

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

snip
what means "implied global" here ? I'd suppose implied is opposed to
explicit ?
*Implicit* is opposed to explicit. Implied means "follows from", as in a
logical conclusion.

Quote:
--

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.

Quote:
This can mask misspelled names and other problems.
Bad causes can have bad effects.

Quote:
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
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.