javascript - Why doesn't this code result in recursion? -


given code:

function foo() {   if (!foo)   {     //blah blah blah code here     foo = true;   } } 

what do? why not creating recursive call?

this might create recursion :

function foo() {   if (!foo()) // <=== notice ()   {     //blah blah blah code here     foo = true;   } } 

but there, without parenthesis, foo isn't executed. tests checks variable foo doesn't evaluate true, , replaces boolean true. it's weird code not recursion.

note we're not sure, inside function, foo function, code :

function foo() {   if (!foo)   {     //blah blah blah code here     foo = true;   } }     var f = foo; foo = 0; f(); // result in foo being true 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -