On Thu, Dec 11, 2008 at 8:41 PM, Henning P. Schmiedehausen <
henn...@schmiedehausen.org> wrote:

>               ^
>
> b) undefined methods:


(snip)

These are all standard browser provided methods. jslint assumes that you're
writing javascript for arbitrary execution environments and as such
complains about anything not explicitly declared. This can be fixed by
adding some funny comments to the source files I believe, but I have no
strong opinion on the matter. The code is absolutely correct.


>
> c) unclear breaks:
>

Yep, that does look pretty ugly.


> d) scary for loops
>
>
(snip)

Yep, hasOwnProperty checks should always be done in object iteration. Any
code that does not do this should be considered a bug.


> f) C'tor names
>
> This is more coding style than anything else. However, most C'tors
> adhere to this, only those fail. Yes, I understand that they probably
> can't be fixed; however then this should be documented. Jslint is a
> standard tool an people will run it on our code base, pointing these
> things out again and again.
>

jslint is wrong here. There is no ctor by those names. These are arguments
to the functions in question. This is the only way to ensure proper scoping
when constructing a variable object name. jslint assumes that nobody would
be silly enough to want to call "constructors" in this fashion, but this is
the only way for this code to work.

Not that I'm defending the actual code in question here, though. I think
this is a fundamentally wrong approach to javascript, but it hasn't caused
any major problems so it's OK by me.

i) functions in loops
>
> That code is a) unreadable and b) error prone. Needs fixing
>

(snip)

There's nothing error prone about these, but I'll buy the readability
argument for the sake of discussion. Javascript is a functional language and
anonymous functions are a perfectly natural feature in the language that any
competent javascript programmer would make good use of. jslint is
complaining because of the potential memory overhead of these declarations
(which are static and don't use any loop data) in a loop. In other words,
it's making a performance argument, not an argument for code quality. You
can find identical constructs in the javascript implementation of jslint
itself, as well as every well-written javascript library in existence.

It turns out that the memory overhead is real on IE6, and that's about it.
So I'll accept that moving these anonymous functions outside of where
they're being used for the memory savings in IE6 is worth it.

Reply via email to