0

Here we have an article about the call stacks and I came across this tidbit: Some programming languages (e.g., Pascal and Ada) support nested subroutines, allowing an inner routine to access the context of its outer enclosing routine, i.e., the parameters and local variables within the scope of the outer routine. Such static nesting can repeat - a function declared within a function declared within a function...

Does JavaScript implement its call stack in a similar manner? Do other languages that support closures differently?

wootscootinboogie
  • 8,461
  • 33
  • 112
  • 197
  • Yes is the answer to your first question. But since SO doesn't allow 3 letter answers I'm leaving it as a comment – slebetman Jan 16 '15 at 04:38
  • @slebetman so I assume it goes that all of the functions are parsed/ran in order of whatever execution context they're in and then call pushed onto the same stack frame? – wootscootinboogie Jan 16 '15 at 04:43
  • Not quite/depends. It depends on what exactly do you mean by that statement. If you think hard about it you'll realize that closures don't quite work the way you describe or work exactly the way you describe depending on what you mean by "then pushed onto the same stack frame" – slebetman Jan 16 '15 at 07:20
  • See my answer to this question on how closures work (ignore the bit in the beginning about private properties): http://stackoverflow.com/questions/26061856/javascript-cant-access-private-properties/26063201#26063201 – slebetman Jan 16 '15 at 07:29
  • @slebetman i'm totally going to steal "a stack frame is an instance of scope" :). thanks for the link. – wootscootinboogie Jan 16 '15 at 14:19

0 Answers0