[Javascript] Literal array declarations
Paul Novitski
paul at juniperwebcraft.com
Thu Oct 29 16:12:52 CDT 2009
At 10/29/2009 12:25 PM, Scott Reynen wrote:
>It's not preferred by everyone, but it is preferred by Douglas
>Crockford, the author of JSLint, and here's a quote from one of his
>books on why he prefers it:
>
>http://stackoverflow.com/questions/383402/is-javascript-s-new-keyword-considered-harmful/383423#383423
>
> > If you forget to include the new prefix when calling a constructor
> > function, then this will not be bound to the new object. Sadly, this
> > will be bound to the global object, so instead of augmenting your
> > new object, you will be clobbering global variables. That is really
> > bad. There is no compile warning, and there is no runtime warning
If omitting the "new" in a "new Array()" construction is bad form,
why not check for that omission specifically instead of forbidding
use of the syntax altogether? I don't mean this as a rhetorical
question; I'd really like to understand Douglas' perspective.
There are many language features in JavaScript that would cause
problems of one sort or another if entered incorrectly. We don't
avoid them, we learn to code correctly. Jslint and validators in
general can be a wonderful help by proofreading our work in detail.
It's when jslint objects to the use of perfectly valid syntax & style
not because the code is incorrect or causing a problem but because
its misuse might cause a problem in some other script someday that
jslint's value as a helper comes into question. I'm seeing jslint not
as a validator, a proofreading assistant in everyday scripting, but
rather as a set of training wheels whose mission is to teach solid
coding practices but that is too strictly idiosyncratic to stay out
from underfoot. I would welcome an argument that would soften this perspective.
Regards,
Paul
__________________________
Paul Novitski
Juniper Webcraft Ltd.
http://juniperwebcraft.com
More information about the Javascript
mailing list