Skip to content

extend

javascript
// 产生一个 Vue 的 子类,即 VueComponent,内部只做一件事,调用 _init 方法进行初始化。

Vue.extend = function (extendOptions) {
    extendOptions = extendOptions || {}
    
    const Super = this // Vue
    const Sub = function VueComponent (options) {
      this._init(options)
    }
    
    // Sub.prototype.__proto__ === Super.prototype
    Sub.prototype = Object.create(Super.prototype)
    Sub.prototype.constructor = Sub
    Sub.options = mergeOptions(Super.options, extendOptions)

    return Sub
}