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来调用。

Logo

前往低代码交流专区

更多推荐