// Apply extends and mixins on the child options, // but only if it is a raw options object that isn't // the result of another mergeOptions call. // Only merged options has the _base property. // 只有合并过的options有_base属性。 if (!child._base) { if (child.extends) { // 处理options.extends的合并 parent = mergeOptions(parent, child.extends, vm) } if (child.mixins) { // 处理child.mixins的合并 for (let i = 0, l = child.mixins.length; i < l; i++) { parent = mergeOptions(parent, child.mixins[i], vm) } } }
const options = {} let key for (key in parent) { mergeField(key) } for (key in child) { if (!hasOwn(parent, key)) { mergeField(key) } } // 选择对应的合并策略。不同的key有不同的合并策略,如data, components, // filters等。合并策略取自config.optionMergeStrategies中,用户可以自定义合并策略。否则,采用默认的合并策略。 functionmergeField (key) { const strat = strats[key] || defaultStrat options[key] = strat(parent[key], child[key], vm, key) } return options }