[英]JavaScript Send a object method as a parameter
我正在尝试将 class 的方法发送到 function,使该方法进入无限循环,我该怎么做?
class MyClass { MyProperty; constructor() { this.MyProperty = "Some value"; } MyMethod() { console.log(this.MyProperty); MyFunction(this.MyMethod); } } function MyFunction(MyParameter){ MyParameter(); } let Test = new MyClass() Test.MyMethod()
class MyClass {
constructor() {
this.MyProperty = "Some value";
}
MyMethod() {
console.log(this.MyProperty);
MyFunction(this.MyMethod.bind(this)); // <<--
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.