views:

45

answers:

1

Why do I get these errors?

Problem at line 329 character 60: Do not use 'new' for side effects.

new widget.StyledDropdown(dojo.byId("sTitle"));

Problem at line 330 character 61: Do not use 'new' for side effects.

new widget.StyledDropdown(dojo.byId("sSuffix"));

Problem at line 336 character 57: Do not use 'new' for side effects.

true,{shortenName : true,maxChars : 20});

Problem at line 338 character 129: Do not use 'new' for side effects.

new widget.StyledDropdown(dojo.byId("sCountry"),USPS.Address.countrySw...

+3  A: 

You're not storing a reference to the newly-created objects, which is a code smell.

JSLint is saying "You're creating some objects but immediately discarding them; the only possible reason you can be doing that is that the act of creating the objects has side-effects, which is weird."

You can lose the warning either by preventing your constructors having side effects (which will mean finding some other way of doing whatever it is they're doing, eg. by moving that code into a normal function) or by storing references to the newly-created objects (even in a temporary local variable that you discard).

RichieHindle
+1, but *God* I hate that term.
T.J. Crowder
If you means "code smell", then so do I, but it is unfortunately quite apt.
Tim Down
@Tim: Yup, that's the one I meant. Why can't we just say "poor practice"?
T.J. Crowder