[英]How to call a specific function from inside a subfunction in javascript?
How do I call function "a" from "av" without a direct reference "a()"如何在没有直接引用“a()”的情况下从“av”调用函数“a”
function a(){
alert("1");
this.v=function(){alert("hi")};
}
One way I can think of doing this without repeating a
:我可以想到这样做而不重复的a
:
function a(){
let indirect = arguments.callee;
alert("1");
indirect.v=function(){ indirect(); };
}
a();
a.v();
But this does not work under strict mode and you must call a
before calling av
.但这在严格模式下不起作用,您必须在调用av
之前调用a
。
You could also do:你也可以这样做:
function a(){
alert('1');
this.v = () => this();
}
a.v = a;
a.v();
This way you don't call a()
and it also works under strict mode.这样你就不会调用a()
并且它也可以在严格模式下工作。
Set its v
property outside the function itself:在函数本身之外设置它的v
属性:
function a() { alert("1"); } av = function() { a() alert("hi") }; av()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.