我一直在阅读有关ES6中的static
方法的信息,我对它们的印象是static
方法主要用于为应用程序创建实用程序功能。
而non-static
方法用于对单个实例化对象执行操作。
现在,我的问题是:
static
和non-static
方法的使用/首选项的方案(类与其实例化的对象)吗?还是还有更多?以下是一个示例:
class Foo {
getStudent() {return 10;}
static getAttendance() {return 20;}
}
console.log(Foo.getStudent); // undefined
console.log(Foo.getAttendance()); // 20
var p = new Foo();
console.log(p.getStudent()); // 10
console.log(p.getAttendance); // undefined