Skip to content

Determine if a function is an ES6 arrow function or not.

License

Notifications You must be signed in to change notification settings

afeiship/is-arrow-fn

Repository files navigation

is-arrow-fn

Determine if a function is an ES6 arrow function or not.

version license size download

installation

npm install @jswork/is-arrow-fn

usage

import isArrowFn from '@jswork/is-arrow-fn';

const obj = {
  fn1() {
    console.log("normal fn1", this);
  },
  fn2: () => {
    console.log("arrow fn2", this);
  },
  fn3: function () {
    console.log("normal fn3", this);
  },
  fn4: function () {
    return () => {
      console.log("123");
    };
  },
};

isArrowFn(obj.fn1); // false
isArrowFn(obj.fn2); // true
isArrowFn(obj.fn3); // false
isArrowFn(obj.fn4); // false

license

Code released under the MIT license.