var defaultData = typeof parentVal === 'function' ? parent.call(vm,vm): parentVal; // -----忘记写
if(InstanceData){
return mergeData(parentVal,childVal)
}else{ // -----忘记写
defaultData
}
}
}
}
strats.data = function(parent,child , key , vm){
if(!vm){
// console.log(typeof child === 'function')
if(child && !(typeof child === 'function')){
warn('data必须返回是一个function')
}
return mergeDataorFn(parent,child)
}
return mergeDataorFn(parent,child,vm)
}
function defaultStrat(parent,child , key , vm){
return child === undefined ? parent :child ;
}
function mergeOptions(parent,child,vm){
var options = {}
// 检测是component 是否是合法的
checkComonpents(child)
// console.log(parent, child)
for(key in parent){
magerField(key)
}
for(key in child){
if(!hasOwn(parent ,key)){ // parent 中循环过地方不进行循环
magerField(key) // ----忘记写
}
}
// 默认合并策略
function magerField(key){
// 自定义策略 默认策略
// console.log(key)
var result = strats[key] || defaultStrat // ---忘记写
options[key] = result(parent[key],child[key] , key , vm)
}
// console.log(options)
return options
}
function initMinxin(options){
Vue.prototype._init = function(options){
var vm = this
// 记录生成的vue实例对象
vm._uip = uip++ // //-------忘记写
vm.$options =mergeOptions(resolveConstructorOptions(vm.constructor),options,vm)
}
}
function Vue(options){
// 安全机制
if(!(this instanceof Vue)){ //-------忘记写
warn('Vue是一个构造函数,必须是由new关键字调用')
}
this._init(options)
}
initMinxin() // 初始化选项1: 规范 2: 合并策略。
Vue.options = {
components: {},
directives:{},
_bash: Vue
}
function initExend(Vue){
Vue.extend = function(extendOptions){
extendOptions = extendOptions || {} // -----忘记写
var Super = this
var Child = function VueComponent() {
this._init(options)
}
Child.prototype = Object.create(Super.prototype)
Child.prototype.constructor = Child // 改变constructor 的指向
Child.options = mergeOptions(Super.options,extendOptions)
// 子类继承父类的静态方法。
Child.extend = Vue.extend
return Child
}
}
initExend(Vue)
return Vue
})
<body>
<div id="app">
<huml></huml>










