You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • ...sure, setIntval() is an immediately executed function with parameters. When passing the - executable - led1 function with parms as first parm - and not just it's reference = it is invokeked and the retrun value is passed as actual parameter - in this case undefined by the definition of the 'intensity_step' functin. The returned value is stored in the time event list / scheduled as the function to call when the interval lapses...

    setInterval(arg0, arg1) is defined as follows: arg0 is either a string (with source code) or a function that can be evaluated respective called on interval lapse.

    Therefore, you could have provided setInterval("led1(0.01)",2); (with led1 known in root context) and that works as well... I don't know about the performance, but generally, I prefere the reference of a function or an anonymous function over the passing of a string, which can be very tricky when having to pass the values of parms that are not as easy as numbers - and even worse -- variable that can change their value (depending on Javascript unique look at scope)... (one of the 'not so nice' side effect of JavaScript....)

About

Avatar for allObjects @allObjects started