JS知识点

158 阅读1分钟

如何判断function是否被new

function Person() {
    console.log(this);
    
    if(typeof this !== 'object') {
        console.log('Person is not call with new');
    }
    else {
        console.log('Person is call with new');
    }
}

Person()
new Person()