Function.prototype.test = function(){return "F"}
function hh(){var x="xx";function test(){return "f"}}
print(hh.test());
结果是“f”,这是否意味着内部函数是外部函数的属性?
==更新了我的代码,但结果仍然是“f”。 !_!
最佳答案
结果应该是一个错误 - 至少在 Chrome 中是这样。
hh
内的 test
是本地函数,不应从外部访问它。
至于Function.test
,它是Function
的属性 - 不是所有函数的成员。如果您确实想让某些东西成为所有函数的成员,则需要将其添加到 Function.prototype
关于javascript - 内部函数是外部函数的属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7765310/