js 函数如何判断是被new还是被函数调用

function Ajanuw() {
  // 函数被new上下问会改变
  if (this instanceof Ajanuw) {
    console.log("new");
  } else {
    console.log("fun");
  }
}

Ajanuw();
new Ajanuw();

函数调用返回自己的实例

const l = console.log;
function Ajanuw() {
  if (!(this instanceof Ajanuw)) {
    return new Ajanuw();
  }
}

l(Ajanuw());     // Ajanuw {}
l(new Ajanuw()); // Ajanuw {}