《javascript设计模式》--接口
关于javascript设计模式书中的接口,记录如下
//TODO 增加了一个判断条件,可以只在生产环境中调用
接口
用法如下:
1 //TODO define Interface
2 var Composite = new Interface('Composite',['add','remove','getChild']);
3 var FormItem = new Interface('FormItem',['save']);
4
5 //TODO checkout implements
6 function addForm(formInstace,isDevelop){
7 isDevelop && Interface.ensureImplements(formInstace, Composite, FormItem)
8 //其他使用add,remove,getchild,save函数的代码段
9 }
10 //CompositeForm class
11 var CompositeForm = function(id, method, action){};
12 CompositeForm.prototype = {
13 add: function(){},
14 remove:function(){},
15 getChild:function(){}
16 ,save:function(){}
17 };
18
19 var testCompositeForm = new CompositeForm()
20 addForm(testCompositeForm,true)
2 var Composite = new Interface('Composite',['add','remove','getChild']);
3 var FormItem = new Interface('FormItem',['save']);
4
5 //TODO checkout implements
6 function addForm(formInstace,isDevelop){
7 isDevelop && Interface.ensureImplements(formInstace, Composite, FormItem)
8 //其他使用add,remove,getchild,save函数的代码段
9 }
10 //CompositeForm class
11 var CompositeForm = function(id, method, action){};
12 CompositeForm.prototype = {
13 add: function(){},
14 remove:function(){},
15 getChild:function(){}
16 ,save:function(){}
17 };
18
19 var testCompositeForm = new CompositeForm()
20 addForm(testCompositeForm,true)