If you use jslint and have read "the good parts," you certainly should be aware of type coercion. Using && and || for flow control doesn't require coercion...
1228
Michael Lorton
mlorton
Mar 12, 2010 11:33 pm
I don't know why you have a smiley at the end there. new Boolean(false) (and new String()) being truthy is a Bad Part. Perhaps :-( is too severe but anything...
1227
Stefan Weiss
weiss@...
Mar 12, 2010 11:19 pm
... What's an empty list? Did you mean an empty Array? Arrays are objects, and all objects are "truthy". Even 'new Boolean(false)' :-) stefan...
1226
walfisch_in_the_sea
walfisch_in_...
Mar 12, 2010 10:35 pm
JSLint is the quickest maintained piece of software I know about. Thank you for that....
1225
Michael Lorton
mlorton
Mar 12, 2010 10:20 pm
My $0.02USD: You should avoid && for flow control not because of any issues with type-coercion. && is an operator and should be treated as an operator: used a...
1224
Stefan Weiss
weiss@...
Mar 12, 2010 10:09 pm
... There's no Autovivification in JS, maybe you were thinking of Perl. Anyway, type coercion can't be the reason for the JSLint error, or this construct would...
1223
Michael Mikowski
z_mikowski
Mar 12, 2010 8:19 pm
Probably because type coercion is considered sloppy programming in any language. In this case, foo[0] test for "truthiness" which means the value must be...
1222
Douglas Crockford
douglascrock...
Mar 12, 2010 7:15 pm
... Thanks. Please try it now....
1221
pauanyu
Mar 12, 2010 7:09 pm
I like this syntax, personally: var MYNS = MYNS || {}; You can also use an "if" for more accurate checks: var MYNS; if (!(MYNS instanceof Object)) { MYNS = {};...
1220
walfisch_in_the_sea
walfisch_in_...
Mar 12, 2010 6:38 pm
Hi, checking this HTML fails because of the + in type: <link rel="alternate" type="application/rss+xml" title="" href="" /> (same with atom+xml) Without, the...
1219
Dave
davehamptonusa
Mar 12, 2010 5:19 pm
Many languages allow a convenience in scripting that allows an && to be used as flow control. var foo = [1,2,3,4]; foo[0] && fop = foo.shift(); //assigns the...
1218
martijnbeulens
Mar 11, 2010 2:00 pm
Hi everybody, I was wondering how to define my root namespace in "strict format" Normally i use the following code: /*global YAHOO, MYNS */ if (!this.MYNS) { ...
1217
Michael Mikowski
z_mikowski
Mar 11, 2010 5:53 am
I stand corrected; YUI compressor 2.4.2 actually throws an exception when using an unquoted reserved word as a key. We never see this because our builds...
1216
Michael Lorton
mlorton
Mar 11, 2010 4:20 am
Eek. A compressor that changes the semantics of the file it's compressing? Admittedly, it's harmless in this case (it's changing it from "doesn39;t work in...
1215
z_mikowski
Mar 11, 2010 2:20 am
If your team uses a build process with a good compressor (e.g. YUI Compressor), it will quote keys as necessary....
1214
Douglas Crockford
douglascrock...
Mar 10, 2010 9:59 pm
... There seem to be two classes of IE users: Those that want to be be using new stuff, and those that want to be using obsolete stuff. Most of the members of...
1213
Dave
davehamptonusa
Mar 10, 2010 9:27 pm
Thanks for the reply. Since I quote all mine, I didn't know JSLint was scrubbing for them. I'll peel back my requirement then, as it just adds characters. ...
1212
Douglas Crockford
douglascrock...
Mar 10, 2010 8:14 pm
... We fixed this in ES5. Once we solve the IE6 problem, it will no longer be necessary to quote reserved words. ... I don't see what this accomplishes. You...
1211
Michael Lorton
mlorton
Mar 10, 2010 8:07 pm
I don't see what problem it solves. If every program is run through JSLint, there is no need for Dave's rule (since the current JSLint mechanism will catch any...
1210
davehamptonusa
Mar 10, 2010 7:59 pm
Many browsers barf when an object key is a reserved word. Sure, they should be able to figure out that we are in an object.... But IE can't.Example: var foop...
1209
Matthew Taylor
mattspratt
Mar 9, 2010 10:42 pm
Here is a lisp procedure that simply adds 'a' to the absolute value of 'b': (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)) I think this is beautiful, and I...
1208
Douglas Crockford
douglascrock...
Mar 8, 2010 8:02 pm
... C's interest in producing an error here is due to its type system. It want to generate different code for void functions than for other types of functions....
1207
Woomla
woomla...
Mar 8, 2010 10:16 am
... Unfortunately I must agree. And I surely don't want to swim againts the current. If you can circumvent the jslint warning by adding return undefined, then...
1206
Satyam
satyamutsa
Mar 7, 2010 5:03 pm
DOM Event listeners can return false to prevent them from doing their default action so it is not just a JavaScript issue but one promoted by the environment...
1205
Stefan Weiss
weiss@...
Mar 7, 2010 12:32 pm
... All JavaScript functions return a value. If you don't specify a return value, they implicitly return undefined, which means that your example could be...
1204
Woomla
woomla...
Mar 7, 2010 11:53 am
If a function does not return anything than it is ok to use return without a value, although I don't consider this as 'best practise'. In my example, however,...
1203
Harry Whitfield
harry152566
Mar 6, 2010 2:24 pm
... new Date() returns an object. +new Date() forces conversion of the object to be a number as if you had used new Date().valueOf(). You could also do that in...
1202
walfisch_in_the_sea
walfisch_in_...
Mar 6, 2010 1:15 pm
+new Date() === new Date().getTime(); +new Date() returns a timestamp. Is this good style? Or should it be avoided?...
1201
Mark Volkmann
mark_volkmann
Mar 5, 2010 4:00 pm
It could be a function that doesn't return anything and return is being used just to exit the function early. In that case using return without a value makes...
1200
Woomla
woomla...
Mar 5, 2010 2:44 pm
The code snippet below doesn't give any errors or warnings. But return with and without a value is used. Shouldn't that at least issue a warning? "use strict";...