文件位置:src/core/instance/index.js
文件地址
为什么要用这样的方式来声明类,而不用class
的方式?
function Vue (options) {
if (process.env.NODE_ENV !== 'production' &&
!(this instanceof Vue)
) {
warn('Vue is a constructor and should be called with the `new` keyword')
}
this._init(options)
}
关于网上的解释说:
”我们往后看这里有很多 xxxMixin 的函数调用,并把 Vue 当参数传入,它们的功能都是给 Vue 的 prototype 上扩展一些方法(这里具体的细节会在之后的文章介绍,这里不展开),Vue 按功能把这些扩展分散到多个模块中去实现,而不是在一个模块里实现所有,这种方式是用 Class 难以实现的。这么做的好处是非常方便代码的维护和管理,这种编程技巧也非常值得我们去学习“
说用class
的方式难以实现?难实现在哪?而且我用 class
的方式代替function
的方式,运行后没有问题
class Vue{
constructor(options){
this._init(options)
}
}
所以为什么要用function
的方式来声明类?
当我没说 当我没说 当我没说