Determine if a function is an ES6 arrow function or not.
npm install @jswork/is-arrow-fn
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
Code released under the MIT license.