Issue
I am trying to send a method of a class to a function, so that this method goes into an infinite loop, how should I do it?
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()
Solution
class MyClass {
constructor() {
this.MyProperty = "Some value";
}
MyMethod() {
console.log(this.MyProperty);
MyFunction(this.MyMethod.bind(this)); // <<--
}
}
Answered By - Eric Fortis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.