Sequelize classMethods vs instanceMethods

后端 未结 3 1567
盖世英雄少女心
盖世英雄少女心 2021-02-12 23:48

So starting my adventure into all things Node. One of the tools I am trying to learn is Sequelize. So I will start off what I was trying to do:



        
3条回答
  •  忘了有多久
    2021-02-13 00:02

    All the method who don't modify or check any type of instance should be classMethod and the rest instanceMethod

    ex:

    // Should be a classMethods
    function getMyFriends() {
      return this.find({where{...}})
    }
    
    // Should be a instanceMethods
    function checkMyName() {
      return this.name === "george";
    }
    

提交回复
热议问题