将类似的方法分组为类静态方法或对象成员有什么区别?
在javascript中,我有两种方法来对类似的方法进行分组:
第一种方法:
class GroupedMethodsWithClass {
static a = () => {
console.log("a")
};
static b = () => {
console.log("b")
}
}
第二种方法:
const GroupedMethodsWithObject = {
a() {
console.log("a");
},
b() {
console.log("b");
},
}
现在我只知道我有 类静态初始化块 选项:
class GroupedMethodsWithClass {
static a = () => {
console.log("a")
}
static b = () => {
console.log("b")
}
static {
console.log('Class static initialization block called');
}
}
但是有谁知道这两种方法之间的真正区别是什么?
In javascript, I have these two approaches to group similar methods:
first approach:
class GroupedMethodsWithClass {
static a = () => {
console.log("a")
};
static b = () => {
console.log("b")
}
}
and the second one:
const GroupedMethodsWithObject = {
a() {
console.log("a");
},
b() {
console.log("b");
},
}
Right now I only know that I have the class static initialization block option with first approach:
class GroupedMethodsWithClass {
static a = () => {
console.log("a")
}
static b = () => {
console.log("b")
}
static {
console.log('Class static initialization block called');
}
}
But does anyone knows what are the real differences between these two approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论