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


Groups > comp.lang.javascript > #30386

Re: Adding data to a function

From Aleksandro <aleksandro@gmx.com>
Newsgroups comp.lang.javascript
Subject Re: Adding data to a function
Date 2016-05-02 20:30 -0300
Organization A noiseless patient Spider
Message-ID <ng8noh$qtg$1@dont-email.me> (permalink)
References <Adding-data-20160502223342@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 02/05/16 18:39, Stefan Ram wrote:
>   The following function always would recompute 
>   »window.document.getElementById( "info" )«.
> 
> "use strict";
> 
> function f()
> { window.document.getElementById( "info" ).innerHTML 
>   = 'The function "f" was called.'; }
> 
>   Is it good style to attach this data to f as a property of f,
>   so that it does not have to be recomputed each time f is
>   being called, i.e.:
>   
> "use strict";
> 
> function f()
> { f.info.innerHTML
>   = 'The function "f" was called.'; }
> f.info = document.getElementById( "info" );
> 
>   ?

If the object is ever destroyed and a new one with the same ID appears,
your function will never see it.

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


Thread

Re: Adding data to a function Aleksandro <aleksandro@gmx.com> - 2016-05-02 20:30 -0300

csiph-web