sequelize / sequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
https://sequelize.org/
MIT License
29.53k stars 4.27k forks source link

instanceMethods with es6 arrow function #5858

Closed xiaofan2406 closed 8 years ago

xiaofan2406 commented 8 years ago

What you are doing?

With Node js moving to es6, it would be great if arrow function works when defining instanceMethods.

module.exports = (sequelize, DataTypes) => {
  const User = sequelize.define('User', {
    name: DataTypes.STRING
  }, {
    instanceMethods: {
      foo: () => { // this is not gonna work as expected
        return this.name
      }
    }
  });
  return User;
};

What do you expect to happen?

above code to work.

What is actually happening?

I may be wrong. I think the lexical scoping is not working in our favor here.

janmeier commented 8 years ago

There is no way to override the scope of arrow functions - that's one of their main features. So there's nothing we can do here

vajanishant commented 6 years ago

can you elaborate why this thing is happening!!! @janmeier