Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11143
| From | Matt McDonald <matt@fortybelow.ca> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Function Declaration as anti-pattern? |
| Date | 2012-02-02 08:25 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <jge9sl$8eb$1@dont-email.me> (permalink) |
| References | <6bs3i7509l7qol48u4i9ac40h85o6n96b3@4ax.com> |
On 12-01-26 05:45 PM, Ross McKay wrote:
> OK, this is different: apparently, the function declaration is now seen
> as an anti-pattern. This doesn't sit comfortably with me; can the
> resident experts please weigh in and discuss?
>
> I can understand Resig's logic in better enabling students to come to
> grips with functions as first-class objects, but... an anti-pattern?
John Resig is not to be trusted as a source of JavaScript
expertise. He is a charlatan of the highest order.
> Perhaps the most interesting change that we can make is a rather subtle
> one, but it's eschewing normal function declarations for creating
> anonymous functions and assigning them to a variable.
>
> // Don't do this:
> function getData() { }
>
> // Do this instead:
> var getData = function() { };
>
> There are a number of good habits that are instilled when you use this
> particular technique.
>
> [function as object, etc]
This is utter nonsense. When one reads jQuery code—typically
from beginners—a common observation is the utter abuse—and
nesting—of anonymous functions. Why? Resig and his acolytes
love the pattern. This anti-pattern is a positively terrible
way to develop an application.
> It enforces good semicolon habits. Traditional function declaration is
> the only situation in which semicolons aren't needed (save for
> conditional statements and loops, naturally) and it makes it much more
> obvious when they're required all the time.
Semicolons really aren't difficult to understand. Any
programmer that's worked in a C-type language (PHP et al.)
knows their importance. The real confusion comes from
people embracing ASI that flaunt their "knowledge"
of ECMAScript.
--
Matt McDonald: Web/Flash Developer; Edmonton, Alberta, Canada
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Function Declaration as anti-pattern? Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-01-27 11:45 +1100
Re: Function Declaration as anti-pattern? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-26 17:34 -0800
Re: Function Declaration as anti-pattern? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-01-26 19:53 -0800
Re: Function Declaration as anti-pattern? John G Harris <john@nospam.demon.co.uk> - 2012-01-27 16:50 +0000
Re: Function Declaration as anti-pattern? Scott Sauyet <scott.sauyet@gmail.com> - 2012-01-30 13:29 -0800
Re: Function Declaration as anti-pattern? Gene Wirchenko <genew@ocis.net> - 2012-01-30 14:37 -0800
Re: Function Declaration as anti-pattern? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-01-31 18:32 +0100
Re: Function Declaration as anti-pattern? Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-02-02 16:20 +1100
Re: Function Declaration as anti-pattern? Matt McDonald <matt@fortybelow.ca> - 2012-02-02 08:25 -0700
Re: Function Declaration as anti-pattern? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-02-02 11:21 -0800
csiph-web