JSFiddle - React, Tailwind, and code Playground
JavaScript
var fns = {
getName: function (fn) {
var match = fn.toString().match(/function\s+([^\s\(]+)/);
return match && match.length ? match[1] : match;
},
fn1: function () {
return this.getName(arguments.callee);
},
fn2: function fn2 () {
return this.getName(arguments.callee);
}
}
console.log('fn1: ', fns.fn1()); // returns null
console.log('fn2: ', fns.fn2()); // returns "fn2"