如何从另一种方法中正确地调用类方法 [英] How to properly call a class method from within another method
本文介绍了如何从另一种方法中正确地调用类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class MyClass {
constructor(){/ * etc * /}
myFunc(){
return myFuncToCall()
}
myFuncToCall(){/ * etc * /}
}
从内调用
? myFuncToCall
的正确方法是什么? myFunc的
解决方案
类语法只是原型继承的语法suger。每个实例方法都是MyClass的原型。
class MyClass {
constructor(){
}
myFunc(){
return this.myFuncToCall()
}
myFuncToCall(){
}
}
Let's say I have the following class:
class MyClass {
constructor () { /* etc */ }
myFunc () {
return myFuncToCall()
}
myFuncToCall () { /* etc */ }
}
What is the correct way to call myFuncToCall
from within myFunc
?
解决方案
the class syntax is just a syntax suger for prototype inheritence. every instance method is on the prototype of MyClass.
class MyClass {
constructor() {
}
myFunc(){
return this.myFuncToCall()
}
myFuncToCall(){
}
}
这篇关于如何从另一种方法中正确地调用类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文