怎么判断是不是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 inst
·
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来调用。
更多推荐
已为社区贡献21条内容
所有评论(0)