EnTerr
12 years agoRoku Guru
Precedence: local vs global function?
What is the precedence (lookup order) when calling a function?
For example say i have defined function exec() in global scope and then inside another function or method i do:
I did a quick tests and seems that global one prevails but this is counter-intuitive. It is customary that binding be resolved to the most local/domestic definition - which in this case is the local assignment of anonymous fn. Doing it the other way risks unpredictable results - say as shown i define and use locally some worker function. All is well while there is no global exec() - but one day somebody adds exec() to a library i use and boom - weird things happen.
For example say i have defined function exec() in global scope and then inside another function or method i do:
exec = function(): return "bar": end functionWhich function should be called?
exec()
I did a quick tests and seems that global one prevails but this is counter-intuitive. It is customary that binding be resolved to the most local/domestic definition - which in this case is the local assignment of anonymous fn. Doing it the other way risks unpredictable results - say as shown i define and use locally some worker function. All is well while there is no global exec() - but one day somebody adds exec() to a library i use and boom - weird things happen.