使用定义函数的变量还是首先使用函数更好?此外,tree-shaking 有区别吗?
我有很多计算(静态)密集型帮助程序类,并且想知道最好的(内存/速度)是什么。
这是我想到的不同方法:
class MyClass {
readonly functionA = (v: string | number, maxDeep: number, curDeep: number = 0): string => {
if (curDeep < maxDeep) {
return this.functionA(v, maxDeep, curDeep + 1);
} else {
return "function A" + v;
}
}
static functionB(v: string | number, maxDeep: number, curDeep: number = 0): string {
if (curDeep < maxDeep) {
return MyClass.functionB(v, maxDeep, curDeep + 1);
} else {
return "function B" + v;
}
}
functionC(v: string …Run Code Online (Sandbox Code Playgroud)