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 {}
来源:https://www.cnblogs.com/ajanuw/p/12550173.html