Evertjan.
5/2/2016 10:06:00 PM
ram@zedat.fu-berlin.de (Stefan Ram) wrote on 02 May 2016 in
comp.lang.javascript:
> 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.: [....]
Methinks "Is it good style to ... ?"
is not a good question,
as it calls for subjective preferences
like "is this a beautiful painting?"
You could ask:
"Is it clearer scripting sourcecode for newbees?"
or
"Does this involve less cpu-time?"
Methinks, the clearer code Q is important, sometimes.
The cpu-time consumption is not, as:
- how many times would you want an innerHTML to change per second?
- the difference in fetching a DOM-pointer from a DOM id-array or as an
object-property [or even as a simple variable] will not matter much imho,
but you could try to measure that for different browsers, if you like.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)