This is a simple task in a web browser but in NodeJS it makes no distinction:
console.log({
// 'Function' in browser, but empty string ('') in NodeJS
'(() => {}).constructor.name': (() => {}).constructor.name,
'(async () => {}).__proto__.constructor.name': (async () => {}).__proto__.constructor.name,
// 'AsyncFunction' in browser, but empty string ('') in NodeJS
'(async () => {}).constructor.name': (async () => {}).constructor.name,
'(async () => {}).__proto__.constructor.name': (async () => {}).__proto__.constructor.name,
// Evaluates to false in browser, but true in NodeJS
'(async () => {}).constructor === (() => {}).constructor': (async () => {}).constructor === (() => {}).constructor,
'(async () => {}).__proto__ === (() => {}).__proto__': (async () => {}).__proto__ === (() => {}).__proto__,
'(async () => {}).__proto__.constructor === (() => {}).__proto__.constructor': (async () => {}).__proto__.constructor === (() => {}).__proto__.constructor,
});
The reason I want to distinguish this is so I can indiscriminately add wrapper code while maintaining the function's "signature". If I were to convert everything to just accept a thenable object via Promise.resolve then I would have to make most all function calls into async methods (or expecting an async thenable). This is a problem for nodejs (or React Native) as it exercises the Promises/A+ specification, so indiscriminately expecting everything to be async does change the functionality of the code.
Does anyone know how to accomplish this or some kind of workaround in the meantime?
.__proto__, it's deprecated. CallObject.getPrototypeOf()instead.'Function','AsyncFunction','AsyncFunction',false,false,false. And that makes sense, since Node.js uses V8, the same JavaScript engine used in the Chromium browsers. I wouldn't expect V8 to work differently in this regard in a browser vs. Node.js. It sounds like you're transpiling or something.