Ahh - well, in the root scope:
function f() { /* do something */ } setInterval(f,intervalTime);
is slightly less efficient than this:
setInterval(function(){ /*do something*/ },intervalTime);
As the first has to also define a named variable for the function.
However,
function f() { /* do something */ } function onInit() { setInterval(f,intervalTime); }
Is definitely more efficient than:
function onInit() { setInterval(function(){ /*do something*/ },intervalTime); }
as the function only exists in memory once. In that last example, it exists in onInit, but after onInit is run, there's another copy in memory.
onInit
Again, that's something that could potentially be changed in the future though - it could just re-use the same characters.
@Gordon started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Ahh - well, in the root scope:
is slightly less efficient than this:
As the first has to also define a named variable for the function.
However,
Is definitely more efficient than:
as the function only exists in memory once. In that last example, it exists in
onInit
, but afteronInit
is run, there's another copy in memory.Again, that's something that could potentially be changed in the future though - it could just re-use the same characters.