Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16201

Re: silly question on closure

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: silly question on closure
Date 2012-09-27 21:29 +0200
Organization albasani.net
Message-ID <k429e2$1rj$1@news.albasani.net> (permalink)
References <a9704993-d83a-4392-8a65-82755e9ba320@u15g2000yql.googlegroups.com> <k3kocg$8ok$1@news.albasani.net> <7227299.QoKgMUOf8L@PointedEars.de> <k40fod$k2d$1@news.albasani.net> <3738235.beI7O1F77D@PointedEars.de>

Show all headers | View raw


On 2012-09-27 20:50, Thomas 'PointedEars' Lahn wrote:
> Stefan Weiss wrote:
>> In the vast majority of cases, JS performance is not a problem
>> (anymore).
> 
> You are very much mistaken.

So you actually believe that, today, JS performance is a problem in the
_vast_ _majority_ of cases? That's funny.

> I have disputed your assertion that closures are to be avoided with a two-
> line function because they would not be worth it in any case.

I'm not surprised that you found something to dispute; seems to be a
hobby of yours. Next time, maybe dispute something I actually said?

When I wrote that the non-closure variant would be better suited, I was
not talking about "in any case", I was referring to one specific
example. Here's that function again:

  function digiName (n) {
      var names = ['zero','one','two','three'];
      return names[n];  // fixed from alert()
  }

This is obviously from an exercise, and not from performance critical
production code. Do we really need a closure here? And assuming this
function is not called thousands of times in a loop (a fair assumption
for this type of training exercise), would you really prefer a closure?

If you do, then that's nice for you, but it's a matter of personal
preference, at best. The result would be harder to read, take up more
space, and the difference in performance would be hardly measurable.

But dispute away, if it makes you happy.

- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-22 05:04 -0700
  Re: silly question on closure Stefan Weiss <krewecherl@gmail.com> - 2012-09-22 18:18 +0200
    Re: silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-22 18:41 -0700
    Re: silly question on closure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-24 01:10 +0200
      Closures (was: silly question on closure) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-24 13:14 +0200
      Re: silly question on closure Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 05:04 +0200
        Re: silly question on closure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-27 20:50 +0200
          Re: silly question on closure Stefan Weiss <krewecherl@gmail.com> - 2012-09-27 21:29 +0200
  Re: silly question on closure "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-22 20:00 +0200
    Re: silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-22 18:42 -0700
      Re: silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-23 07:31 -0700
        Re: silly question on closure Stefan Weiss <krewecherl@gmail.com> - 2012-09-23 18:49 +0200
          Re: silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-23 13:33 -0700
          Re: silly question on closure justaguy <lichunshen84@gmail.com> - 2012-09-23 13:38 -0700
            Re: silly question on closure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-24 20:49 +0200
    Re: silly question on closure Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-24 01:14 +0200
  Re: silly question on closure dann90038@gmail.com - 2012-09-23 15:37 -0700

csiph-web