var Class = {
extend:function({initialize,members,protos}){
var _this = this;
// _this.f = _this.prototype.deepClone;
var newClass = function(options){
//静态成员
// var members = members || {};
var newMember = _this.prototype.deepClone(members);
for(var i in newMember){
this[i] = newMember[i];
}
//实例化时的参数对象也并到实例成员中
var options = options||{};
if(_this.prototype.isObj(options)){
for(var i in options){
if(this[i] && _this.prototype.isObj(this[i])){
this[i] = {
...this[i],
...options[i]
}
}else{
this[i] = options[i];
}
}
}
//执行初始化方法
initialize && initialize.call(this);
// this.extend = _this.extend;
}
newClass.extend = _this.extend
//原型继承
newClass.prototype = {
..._this.prototype,
...protos||{}
};
return newClass;
},
prototype:{
class_f:function(){
},
isObj:function(o) {
return Object.prototype.toString.call(o) === '[object Object]';
},
isFun:function(o) {
return Object.prototype.toString.call(o) === '[object Function]';
},
isArr:function(o) {
return Object.prototype.toString.call(o) === '[object Array]';
},
isNum:function(o) {
return Object.prototype.toString.call(o) === '[object Number]';
},
isBool:function(o) {
return Object.prototype.toString.call(o) === '[object Boolean]';
},
isStr:function(o) {
return Object.prototype.toString.call(o) === '[object String]';
},
deepClone:function(obj) {
var f = obj=>{
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (obj instanceof Date) {
return new Date(obj.getTime());
}
if (obj instanceof Array) {
return obj.reduce((arr, item, i) => {
arr[i] = f(item);
return arr;
}, []);
}
if (obj instanceof Object) {
return Object.keys(obj).reduce((newObj, key) => {
newObj[key] = f(obj[key]);
return newObj;
}, {});
}
}
return f(obj);
}
}
}
var A = Class.extend({
members:{
a1:1,
eventContainer:{
'click':[]
}
},
initialize:function(){
},
protos:{
a_f:function(){
console.log('a_f');
}
}
})
// console.log(Class)
var a1 = new A();
a1.a1 = 2;
a1.eventContainer['click'].push('a1---click');
var a2 = new A();
console.log('a1');
console.log(a1);
console.log('a2');
console.log(a2);
// var B = A.extend({
// members:{
// b1:1,
// eventContainer:{
// 'click':[]
// }
// },
// initialize:function(){
// },
// protos:{
// }
// })
// var b1 = new B();
// b1.eventContainer['click'].push('456')
// console.log('b1')
// console.log(b1);
console