There are three variables with the same name (value), but with different values. How can one of these three variables be read from a nested function?
(the question is not practical, but theoretical, so the proposals to call them differently, pass in the parameters taken by functions, etc. do not fit. What you want to understand is to use it by analogy with AS - examples below)
var value = "global" function f1() { var value = "external"; function f2() { var value = "internal"; alert(any code 1?) // global alert(any code 2?) // external alert(any code 3?) // internal } } In ActionScript, this is pretty easy:
var _value = "global" function f1() { var _value = "external"; function f2() { var ext=_value var _value = "internal"; trace(_root._value) // works: global trace(ext) // works: external trace(_value) // works: internal } f2() } f1() Also in ActionScript, you can use an activation object (but in JS as far as I know there is no access to it):
var _value = "global" function f1() { var _value = "external"; function f2() { _value // связываем объект активации f1 с f2 var _value = "internal"; trace(_root._value) // works: global trace(this._value) // works: external trace(_value) // works: internal } f2() } f1()