![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = []; as opposed to using a constructor var arr2 = new Array(); I've been a-googling, but the best reason for this that I can find is "because it's not necessary to use a constructor". I'm wondering: 1) Is there a way to tell the difference between arr1 and arr2 as defined above, once they've been defined? |
|
2) Is there anything, beyond stylstic reasons, to prefer one method over another? |
#3
| |||
| |||
|
|
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = []; as opposed to using a constructor var arr2 = new Array(); I've been a-googling, but the best reason for this that I can find is "because it's not necessary to use a constructor". I'm wondering: 1) Is there a way to tell the difference between arr1 and arr2 as defined above, once they've been defined? |
|
2) Is there anything, beyond stylstic reasons, to prefer one method over another? |
|
I've no problem against JSLint choosing a specific convention and applying it. I'm just wondering if there is anything *beyond* convention to speak in favour of literal over constructor notation. |
#4
| |||
| |||
|
|
I've no problem against JSLint choosing a specific convention and applying it. I'm just wondering if there is anything *beyond* convention to speak in favour of literal over constructor notation. I don't have a problem with this particular convention. The only time I can |
#5
| |||
| |||
|
|
Dan Rumney <danrumney (AT) warpmail (DOT) net> wrote: I've no problem against JSLint choosing a specific convention and applying it. I'm just wondering if there is anything *beyond* convention to speak in favour of literal over constructor notation. I do have issues with some of the other warnings generated by jslint which is why I produced a modified version that lets you ignore particular error messages if you don't like them. |
#6
| |||
| |||
|
|
I think it's wrong for it to be called jslint when really it should be called jscrockford. |
#7
| |||
| |||
|
|
On Jun 12, 7:35 pm, Stevo <n... (AT) mail (DOT) invalid> wrote: I think it's wrong for it to be called jslint when really it should be called jscrockford. :-) Fully sustained. jslint as it is right now is just like some C checker which would mark missing closing brackets - and at the same time would issue errors for each opening bracket placed on the same line as the method name (or below it). So it is a rather strong cocktail of a code checker and a particular pretty-print enforcer. Still the author is fairly fair about it: http://tech.groups.yahoo.com/group/jslint_com/ "Warning: JSLint will hurt your feelings." Moreover no one is forcing to use JSLint as some "final authoritative validity" tool. |
|
One plus of [] is that it makes the code uniformly looking with JSON data. With Mr. Crockford being the author of JSON, this is - I guess - the core of the JSLint's "bracket obsession" :-) |
I'd like to say
#8
| |||
| |||
|
|
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = []; as opposed to using a constructor var arr2 = new Array(); |
#9
| |||
| |||
|
|
The bracket notation is preferred always. It is smaller and more consistent. [] and new Array() do the same thing. [1, 2] and new Array(1, 2) do the same thing. [1] and new Array(1) do not do the same thing. [undefined] and new Array(1) do extremely similar things. http://www.JSLint.com/ |
#10
| |||
| |||
|
|
I've been taking a look at Douglas Crockford's JSLint. One of the conventions that it expects is that arrays be created using literal notation var arr1 = []; as opposed to using a constructor var arr2 = new Array(); I've been a-googling, but the best reason for this that I can find is "because it's not necessary to use a constructor". I'm wondering: 1) Is there a way to tell the difference between arr1 and arr2 as defined above, once they've been defined? |
|
2) Is there anything, beyond stylstic reasons, to prefer one method over another? |
![]() |
| Thread Tools | |
| Display Modes | |
| |