简体   繁体   中英

is the inner function a property of outer function?

Function.prototype.test = function(){return "F"}
function hh(){var x="xx";function test(){return "f"}}

print(hh.test());

the result is "f", does that mean the inner function is a property of outer function?

== updated my code, but the result is still "f". !_!

The result should be an error - and at least in Chrome, it is.

test inside hh is a local function, and it should not be accessible from outside.

As for Function.test , it is a property of Function - not a member of all functions. If you actually want to make something a member of all functions, it needs to be added to Function.prototype

You actually managed to get a result from this code? You are trying to print the result.

hh.test will be undefined as test is being defined privately to hh. Defining test on the prototype Function.prototype.test would return 'F' from hh.test in this instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM