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


Groups > comp.lang.javascript > #17417

Re: Problem w/ creating dynamic TR and its TDs

Message-ID <1562636.Ll19dNWgsJ@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-12-02 19:39 +0100
Subject Re: Problem w/ creating dynamic TR and its TDs
Newsgroups comp.lang.javascript
References (2 earlier) <5462881.fXVs31Ce0e@PointedEars.de> <k9f0rg$ajv$1@speranza.aioe.org> <5551855.fYihAxhPQP@PointedEars.de> <k9g4a1$54q$1@speranza.aioe.org> <2075691.byxZkP05Om@PointedEars.de>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Thomas 'PointedEars' Lahn wrote:

> Consider this instead:
> 
>   for (var key in params)
>   {
>     if (params.hasOwnProperty(key))
>     {
>       // …
>     }
>   }
> 
> The least you should do is to cache the value of
> `Object.prototype.hasOwnProperty', maybe even in a bound variable of a
> closure (as can be seen in JSX), if you do not call it through the
> prototype chain.
> 
>   /*
>    * Or `Object.prototype', but `{}' appears to have a shorter
>    * scope chain, which might win over the longer prototype chain
>    */
>   var _hasOwnProperty = {}.hasOwnProperty;
> 
>   for (var key in params)
>   {
>     if (_hasOwnProperty.call(params, key))
>     {
>       // …
>     }
>   }
> 
> It might be useful to combine these:
> 
>   var hasHasOwnProperty =
        ^^^^^^^^^^^^^^^^^
That must _hasOwnProperty.  I wrote the hasHasOwnProperty() approach later 
but it did not work well with boolean expressions, so I reverted it (only 
partially, apparently).

>     (typeof params.hasOwnProperty == "function")
>       ? params.hasOwnProperty
>       : {}.hasOwnProperty;
> 
>   for (var key in params)
>   {
>     if (_hasOwnProperty.call(params, key))
>     {
>       // …
>     }
>   }


PointedEars
-- 
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
  -- Richard Cornford, cljs, <f806at$ail$1$8300dec7@news.demon.co.uk>

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


Thread

Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 15:17 -0800
  Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 00:34 +0100
    Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 17:06 -0800
    Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 03:46 +0100
      Re: Problem w/ creating dynamic TR and its TDs justaguy <lichunshen84@gmail.com> - 2012-12-01 19:27 -0800
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 22:53 +0100
      Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 08:43 +0100
        Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 16:11 +0100
          Re: Problem w/ creating dynamic TR and its TDs Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-12-02 18:48 +0100
            Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:35 +0100
              Re: Problem w/ creating dynamic TR and its TDs Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 19:39 +0100

csiph-web