[英]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? 结果为“ f”,是否表示内部函数是外部函数的属性?
== updated my code, but the result is still "f". ==更新了我的代码,但结果仍然是“ f”。 !_!
!_!
The result should be an error - and at least in Chrome, it is. 结果应该是错误-至少在Chrome中是这样。
test
inside hh
is a local function, and it should not be accessible from outside. hh
内部的test
是局部函数,不应从外部访问。
As for Function.test
, it is a property of Function
- not a member of all functions. 至于
Function.test
,它的属性Function
-不是所有功能的成员。 If you actually want to make something a member of all functions, it needs to be added to Function.prototype
如果您实际上想使某个东西成为所有函数的成员,则需要将其添加到
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. hh.test
将是未定义的,因为test
是私自定义为hh。 Defining test on the prototype Function.prototype.test
would return 'F' from hh.test
in this instance. 在这种情况下,在原型
Function.prototype.test
上定义test将从hh.test
返回'F'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.