A) What is the difference between line 1 and 2 below?
function b() { console.log("b()"); }
var b = function() { console.log("b()"); };
B) With A) answered, what is the difference between the two blocks below?
function a() {
function b() { console.log("b()"); }
setTimeout(b,500);
}
function a() {
var b = function(){ console.log("b()"); }
setTimeout(b,500);
}
C):
if you called it twice it'd be able to use the same copy of b's code, saving memory.
I assume you mean: called it twice within funcation a(), correct?
I expect that assigning a function to a variable var b = function(){} is just putting a pointer - like the entry point of the function (the source address) - into the (scoped) variable - same as function b(){} , and then 'skips' the whole function in regard of execution 'to just find the end of the function' in order to resume execution.
function b parsed beforehand, so execution would be faster.
...is that not a contradiction to Espruino executes from source code?
Because what is created on parsing? If it is more than some 'isParsed' flag that is stored within the 'variable/function' value reference store, then it goes towards JIT compiling and uses unpredictable amounts of memory. And if it is just a flag, what would be the use of it? ...so far I did not find the time - or guts(?) - yet to dive into the interpreter's gut (source code).
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.
Assumed in the top / global level:
A) What is the difference between line 1 and 2 below?
B) With A) answered, what is the difference between the two blocks below?
C):
I assume you mean: called it twice
within funcation a()
, correct?I expect that assigning a function to a variable
var b = function(){}
is just putting a pointer - like the entry point of the function (the source address) - into the (scoped) variable - same asfunction b(){}
, and then 'skips' the whole function in regard of execution 'to just find the end of the function' in order to resume execution....is that not a contradiction to Espruino executes from source code?
Because what is created on parsing? If it is more than some 'isParsed' flag that is stored within the 'variable/function' value reference store, then it goes towards JIT compiling and uses unpredictable amounts of memory. And if it is just a flag, what would be the use of it? ...so far I did not find the time - or guts(?) - yet to dive into the interpreter's gut (source code).