class方法和实例方法有什么区别[sequelize]

What is the difference between class methods and instance methods [sequelize]

Sequelize 允许您将自定义方法添加到 model,有两种方法可以这样做:

在Sequelize中我找不到关于这两个对象的区别的解释。谁能举例说明何时使用其中一个或另一个的区别?

Class就是调用sequelize.define时得到的对象。代表整个table.

var User = sequelize.define('user', {...});

实例就像 class 的一个单元,即集合 table:

中的一行
User.create({}).then(function(user) {
  // `user` is an instance.
});

Class 方法是不需要实例的函数。你可以这样称呼它们:

User.myMethod();

实例方法是在单个实例上运行的方法。你可以这样称呼他们:

user.myMethod();

this 在 class 方法中是一个 class。 this 在实例方法中是一个实例(显然)。