- function diqye (argument) {}
- diqye.decorator = function(type,parent){
- parent.type=type;
- var _regs={};
- var _parent = parent;
- var result = function(name,parentName,decorator,cfg){
- if(typeof parentName === "string"){
- _parent = _regs[parentName];
- _parent = _parent.prototype;
- }else{
- cfg = decorator;
- decorator = parentName;
- }
- if(typeof decorator === 'function'){
- var result1 = _regs[name]=function(options){
- this.init(options);
- }
- var dec = decorator(_parent);
- for(key in _parent){
- result1.prototype[key]=_parent[key];
- }
- for(key in dec){
- result1.prototype[key]=dec[key];
- }
- result1.prototype.type=name;
- result1.prototype.parent = _parent;
- }else{
- cfg = decorator;
- }
- if(cfg){
- return new _regs[name](cfg);
- }
- }
- result.add = function(key,value){
- _parent[key]=value;
- }
- return result;
- }
- diqye.base = diqye.decorator('c1',{
- init:function(options){
- console.log("==============c1 init method==============");
- console.log(options);
- },
- method1:function(){
- console.log("===========method1===================");
- }
- });
- diqye.base('c11',function(parent){
- return {
- init:function(options){
- parent.init.call(this,options);
- console.log("==============c11 init method==============");
- }
- }
- });
- diqye.base('c111','c11',function(parent){
- return {
- init:function(options){
- console.log(this);
- parent.init.call(this,options);
- console.log("==============c111 init method==============");
- }
- }
- });
- diqye.base('c111',[1,2]).method1();
- //该片段来自于http://www.codesnippet.cn/detail/2309201410496.html
来源: http://www.codesnippet.cn/detail/2309201410496.html