怎么判断是不是new创建的
Posted 前端精髓
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么判断是不是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来调用。
以上是关于怎么判断是不是new创建的的主要内容,如果未能解决你的问题,请参考以下文章