Is there an elegant way to tell Harmony\'s slim arrow functions apart from regular functions and built-in functions?
The Harmony wiki states that:>
I wrote this for Node, should work in Chrome as well.
"Boundness" is detected (apparently, only on ES6) and reported as native && bound
. This might or might not be an issue, depending on what you are using that information for.
const flags = {
function: f instanceof Function,
name: undefined,
native: false,
bound: false,
plain: false,
arrow: false
};
if (flags.function) {
flags.name = f.name || '(anonymous)';
flags.native = f.toString().trim().endsWith('() { [native code] }');
flags.bound = flags.native && flags.name.startsWith('bound ');
flags.plain = !flags.native && f.hasOwnProperty('prototype');
flags.arrow = !(flags.native || flags.plain);
}
return flags;