vue 的 起手式

代码:

vue.js

// vue 起手势
(function(root,factory) {
	root.Vue = factory();
})(this,function(){
	// 设置基础的默认配置
	var DAFALUT = {
		el:"body",
		data:{}
	}
	var Vue = function(options){ // options用户传的参数  以默认优先 以用户配置为覆盖
		// this指向vue的实例
		// 扩展(在vue的原型上)
		this.extend(this, DAFALUT,options); // 将DAFALUT的属性扩展到this上

		console.log(this.el);
		this.observer();
	}

	Vue.prototype = {
		extend:function(){ // 对象扩展
			// arguments 用于用户调用时传入的参数
			for(var i=1;i<arguments.length;i++){ // 从1开始,不需要循环this
				// for in 可枚举属性, 针对对象
				for(var name in arguments[i]){ // 0
					this[name] = arguments[i][name]
					// el data
				}
			}
		},
		observer:function(){ // model 观察者模式
			for(var key in this.data){
				//
			}
		}
	}

	return Vue;
});

new Vue({
	el:"app"
});

// var obj = {
// 	//
// }
// obj.name
// obj[name]

// $.extend(true, target object, object)

.

原文地址:https://www.cnblogs.com/crazycode2/p/7224951.html