0
点赞
收藏
分享

微信扫一扫

怎么判断是不是new创建的


function Vue (options) {
if (!(this instanceof Vue)) {
console.warn('Vue is a constructor and should be called with the `new` keyword')
}
// this._init(options)
}

在读vue源码的时候我发现一行代码,还挺有意思的,那就是条件语句中 ​​this instanceof Vue​​ 代码,其实这个代码就是判断该函数只能通过new来调用。


举报

相关推荐

0 条评论