MCPcopy Index your code
hub / github.com/ygs-code/vue / initExtend

Function initExtend

vue.js:6994–7097  ·  view source on GitHub ↗
(Vue)

Source from the content-addressed store, hash-verified

6992 /* */
6993 //初始化 vue extend 函数
6994 function initExtend(Vue) {
6995 /**
6996 * Each instance constructor, including Vue, has a unique
6997 * cid. This enables us to create wrapped "child
6998 * constructors" for prototypal inheritance and cache them.
6999 */
7000 Vue.cid = 0;
7001 var cid = 1;
7002
7003 /**
7004 Vue.extend//使用基础 Vue 构造器,创建一个“子类”。参数是一个包含组件选项的对象。合并继承new 实例化中的拓展参数或者是用户直接使用Vue.extend 的拓展参数。把对象转义成组件构造函数。创建一个sub类 构造函数是VueComponent,合并options参数,把props属性和计算属性添加到观察者中。//如果组件含有名称 则 把这个对象存到 组件名称中, 在options拓展参数的原型中能获取到该数据Sub.options.components[name] = Sub 简称Ctor,返回该构造函数
7005 */
7006 Vue.extend = function (extendOptions) { //使用基础 Vue 构造器,创建一个“子类”。参数是一个包含组件选项的对象。
7007
7008 extendOptions = extendOptions || {};
7009 var Super = this;
7010 var SuperId = Super.cid;
7011 var cachedCtors = extendOptions._Ctor || (extendOptions._Ctor = {}); //组件构造函数
7012 if (cachedCtors[SuperId]) { //父类 超类id
7013 return cachedCtors[SuperId] //获取 超类
7014 }
7015 var name = extendOptions.name || Super.options.name; //获取组件的name
7016 if ("development" !== 'production' && name) {
7017 // 验证组件名称 必须是大小写,并且是-横杆
7018 validateComponentName(name);
7019 }
7020 //实例化 组件 对象
7021 var Sub = function VueComponent(options) {
7022 console.log('==this._init')
7023 console.log(this._init)
7024
7025 // vue中的_init 函数 Vue.prototype._init
7026 this._init(options);
7027 };
7028 //创建一个对象 继承 超类的原型
7029 Sub.prototype = Object.create(Super.prototype);
7030 //让他的构造函数指向回来,防止继承扰乱。
7031 Sub.prototype.constructor = Sub;
7032 //id 加加。标志 不同的组件
7033 Sub.cid = cid++;
7034 //合并参数
7035 Sub.options = mergeOptions(
7036 Super.options,
7037 extendOptions
7038 );
7039 //记录超类
7040 Sub['super'] = Super;
7041
7042 // For props and computed properties, we define the proxy getters on
7043 // the Vue instances at extension time, on the extended prototype. This
7044 // avoids Object.defineProperty calls for each instance created.
7045 //对于道具和计算属性,我们定义代理getter
7046 //在扩展原型上的扩展时的Vue实例。这避免为创建的每个实例调用Object.defineProperty。
7047 if (Sub.options.props) { //获取props属性 如果有
7048 //初始化属性 并且把组件的属性 加入 观察者中
7049 initProps$1(Sub);
7050 }
7051 if (Sub.options.computed) { //组件计算属性

Callers 1

initGlobalAPIFunction · 0.85

Calls 5

validateComponentNameFunction · 0.85
mergeOptionsFunction · 0.85
initProps$1Function · 0.85
initComputed$1Function · 0.85
extendFunction · 0.85

Tested by

no test coverage detected