Widget Tester Widget (version 8.2) with JSLint 2009-04-30 is now at http://tinyurl.com/5unocx . This version has the option to download and use the latest...
458
pauanyu
May 1, 2009 4:23 pm
var global; (function () { var local; }()); Note that it lists local as Unused, but not global. I'm not sure if this is considered a bug or not, but it seems a...
459
Michael Lorton
mlorton
May 1, 2009 4:26 pm
In a formal sense, it's a bug, but how could it be fixed? A global variable might be used by a different script, or by a bit of Javascript in an event...
460
pauanyu
May 1, 2009 4:31 pm
test = function () {}; self.test = function () {}; window.test = function () {}; test(); JSLint sees the first three lines as different, even though they are...
461
pauanyu
May 1, 2009 4:36 pm
... As to your first point.. JSLint supports the /*global */ construct for global variables defined elsewhere....
462
Michael Lorton
mlorton
May 1, 2009 4:47 pm
The /*global */ tag solves the reverse problem: how tell if a variable used here is declared elsewhere. Perhaps we need a /*external */ tag that asserts a...
463
Jakob Kruse
thekrucible
May 1, 2009 4:53 pm
I believe that unless you are in a browser, ”test” would be undefined in this case. First example is missing a “var”, second and third defines...
464
pauanyu
May 1, 2009 5:03 pm
... Yes, and there's an "assume a browser" option that specifies browser objects (like window). You also don't need a var to declare a global variable, but...
465
Jakob Kruse
thekrucible
May 1, 2009 8:25 pm
Actually, that is very common. The purpose of most libraries is to declare global variables for use elsewhere. /Jakob From: jslint_com@yahoogroups.com...
466
Jakob Kruse
thekrucible
May 1, 2009 8:37 pm
Again, the ”assume a browser” option of JSLint, AFAIK, only means that you don’t have to explicitly define the global object “window” and others. It...
467
Douglas Crockford
douglascrock...
May 1, 2009 9:36 pm
The /*jslint */ comment can now specify the indent....
468
Douglas Crockford
douglascrock...
May 1, 2009 9:47 pm
... What are you proposing, that JSLint not allow access to window and self when assuming a browser? I think that is a reasonable restriction. A better...
469
Merlin
harry152566
May 1, 2009 10:58 pm
... I agree....
470
santini.alberto
May 1, 2009 11:05 pm
... Using JavaScript also in a server-side context, "test", "self.test" and "window.test" are three different things. For me the actual behaviour is ok. ...
471
pauanyu
May 2, 2009 4:07 am
... No, my proposal is that since declaring a global variable with var is exactly the same as assigning a property to the window object, JSLint should be...
472
Michael Lorton
mlorton
May 2, 2009 4:53 am
Declaring a global variable with var is not the same as assigning a property to the window object. In a browser, the two actions have the same effect, but a....
473
Michael Lorton
mlorton
May 2, 2009 5:01 am
You're right, of course, but even a library should avoid polluting the global names space any more than necessary. I prefer to have all the library's...
474
crlender
May 2, 2009 8:30 am
... Yes, you do. Without "var", you're not creating a variable, but a property of the global object, which in the case of browsers is window (aka self). ... ...
475
Douglas Crockford
douglascrock...
May 2, 2009 2:29 pm
The "Assume a browser" no longer supplies 'window39; and 'self'. Having multiple representations of global variable access is a source of confusion. When feature...
476
Mike West
mikewest_y
May 3, 2009 8:37 am
Douglas, I appreciate your diligence in keeping the list up-to-date with the latest changes as you deploy them. Is there any chance that you could be persuaded...
477
pauanyu
May 4, 2009 5:30 pm
... I am curious, why is: if (typeof foo === 'undefined39;) { better than: if (!foo) { ?...
478
crlender
May 4, 2009 5:59 pm
... In your example, if foo is not declared, it will result in a ReferenceError being thrown. This won't happen if you test with the typeof operator. I think...
479
christian.wirkus
christian.wi...
May 5, 2009 12:01 pm
Hello! I think really neat would be something that generates the jslint-options-string (/*jslint ... */). I am writing a small Javascript Library and had the...
480
pauanyu
May 5, 2009 12:48 pm
... I see; thank you. Another question, why use: if (typeof console === 'object39;) { Instead of: if (console instanceof Object) { ? As far as I know, if...
481
Jakob Kruse
thekrucible
May 5, 2009 4:12 pm
I disagree. Not with the ”single object” approach, that is a very good practice, but that libraries usually refer to themselves. I have a multitude of...
482
Michael Lorton
mlorton
May 5, 2009 4:23 pm
Really? Your libraries never have externally available functions or data that they themselves use? You could always do this, I suppose: var myModule = (...
483
Jakob Kruse
thekrucible
May 5, 2009 5:21 pm
Yes, really. I fail to see why I would want to reference the global from within its own declaration? That said, this discussion has gotten quite a bit off...
484
pauanyu
May 5, 2009 5:52 pm
... I agree, but the idea was to be more of a helpful hint. If you declare a variable but don't use it, JSLint doesn't throw an error. Instead, it lists the...
485
crlender
May 5, 2009 6:54 pm
Internet Explorer has a window.execScript() method that basically does the same thing as eval(), except that it always executes scripts in the global scope: ...
486
Douglas Crockford
douglascrock...
May 6, 2009 12:57 am
... Interesting idea. http://www.JSLint.com/index.html now provides assistance in building /*jslint*/ and /*global*/ comments....