设计模式知识连载(1)---函数的书写方式
来源:互联网 发布:短信发送平台源码 编辑:程序博客网 时间:2024/06/06 09:54
<body><script type="text/javascript">/** * 形式一: */// function checkName() {// console.log('checkName running_1') ;// } ;// function checkEmail() {// console.log('checkEmail running_1') ;// } ;// function checkPassword() {// console.log('checkPassword running_1') ;// } ;// checkName() ;// checkEmail() ;// checkPassword() ;/** * 形式二: */// var checkName = function() {// console.log('checkName running_2') ;// } ;// var checkEmail = function() {// console.log('checkEmail running_2') ;// } ;// var checkPassword = function() {// console.log('checkPassword running_2') ;// } ;// checkName() ;// checkEmail() ;// checkPassword() ;/** * 形式三: */// var CheckObject = {// checkName : function() {// console.log('checkName running_3') ;// },// checkEmail : function() {// console.log('checkEmail running_3') ;// }, // checkPassword : function() {// console.log('checkPassword running_3') ;// }// } ;// CheckObject.checkName() ;// CheckObject.checkEmail() ;// CheckObject.checkPassword() ;/** * 形式四: */// var CheckObject = function() {};// CheckObject.checkName = function() {// console.log('checkName running_4') ;// } ;// CheckObject.checkEmail = function() {// console.log('checkEmail running_4') ;// } ;// CheckObject.checkPassword = function() {// console.log('checkPassword running_4') ;// } ;// CheckObject.checkName() ;// CheckObject.checkEmail() ;// CheckObject.checkPassword() ;/** * 形式五: */// var CheckObject = function() {// return {// checkName : function() {// console.log('checkName running_5') ;// },// checkEmail : function() {// console.log('checkEmail running_5') ;// },// checkPassword : function() {// console.log('checkPassword running_5') ;// }// }// }// var co = CheckObject() ;// co.checkName() ;// co.checkEmail() ;// co.checkPassword() ;/** * 形式六: */// var CheckObject = function() {// this.checkName = function() {// console.log('checkName running_6') ;// } ;// this.checkEmail = function() {// console.log('checkEmail running_6') ;// } ;// this.checkPassword = function() {// console.log('checkPassword running_6') ;// }// } ;// var co = new CheckObject() ;// co.checkName() ;// co.checkEmail() ;// co.checkPassword() ;/** * 形式七-1: */// var CheckObject = function() {} ;// CheckObject.prototype.checkName = function() {// console.log('checkName running_7') ;// } ;// CheckObject.prototype.checkEmail = function() {// console.log('checkEmail running_7') ;// } ;// CheckObject.prototype.checkPassword = function() {// console.log('checkPassword running_7') ;// }// var co = new CheckObject() ;// co.checkName() ;// co.checkEmail() ;// co.checkPassword() ;/** * 形式七-2: */// var CheckObject = function() {} ;// CheckObject.prototype = {// checkName : function() {// console.log('checkName running_7-2') ;// },// checkEmail : function() {// console.log('checkEmail running_7-2') ;// }, // checkPassword : function() {// console.log('checkPassword running_7-2') ;// }// } ;// var co = new CheckObject() ;// co.checkName() ;// co.checkEmail() ;// co.checkPassword() ;/** * 形式八-1: */// var CheckObject = {// checkName : function() {// console.log('checkName running_8-1') ;// return this ;// },// checkEmail : function() {// console.log('checkEmail running_8-1') ;// return this ;// },// checkPassword : function() {// console.log('checkPassword running_8-1') ;// return this ;// }// } ;// CheckObject.checkName().checkEmail().checkPassword() ;/** * 形式八-2: */// var CheckObject = function() {} ;// CheckObject.prototype = {// checkName : function() {// console.log('checkName running_8-2') ;// return this ;// },// checkEmail : function() {// console.log('checkEmail running_8-2') ;// return this ;// },// checkPassword : function() {// console.log('checkPassword running_8-2') ;// return this ;// }// } ;// var co = new CheckObject() ;// co.checkName().checkEmail().checkPassword() ;/** * 形式九-1(prototype.js): */// Function.prototype.checkName = function() {// console.log('checkName running_9-1[prototype.js]') ;// } ;// // 函数形式// var f1 = function() {}; // f1.checkName() ;// // 类形式// var f2 = new Function() ;// f2.checkName() ;/** * 形式九-2(prototype.js): */// Function.prototype.addMethods = function(name, fn) {// this[name] = fn ;// } ;// // 函数形式// var methods1 = function() {} ;// // 类形式// var methods2 = new Function() ;// methods1.addMethods('checkName', function() {// console.log('checkName running_9-2[prototype.js]') ;// }) ;// methods2.addMethods('checkEmail', function() {// console.log('checkEmail running_9-2[prototype.js]') ;// }) ;// methods1.checkName() ;// methods2.checkEmail() ;/** * 形式十-1(prototype.js): */// Function.prototype.addMethods = function(name, fn) {// this[name] = fn ;// return this ;// } ;// var methods = new Function() ;// methods.addMethods('checkName', function() {// console.log('checkName running_10-1[prototype.js]') ;// }).addMethods('checkEmail', function(){// console.log('checkEmail running_10-1[prototype.js]') ;// }).addMethods('checkPassword', function() {// console.log('checkPassword running_10-1[prototype.js]') ;// }) ;// methods.checkName() ;// methods.checkEmail() ;// methods.checkPassword() ;/** * 形式十-2(prototype.js): */// Function.prototype.addMethods = function(name, fn) {// this[name] = fn ;// return this ;// } ;// var methods = new Function() ;// methods.addMethods('checkName', function() {// console.log('checkName running_10-2[prototype.js]') ;// return this ;// }).addMethods('checkEmail', function() {// console.log('checkEmail running_10-2[prototype.js]') ;// return this ;// }).addMethods('checkPassword', function() {// console.log('checkPassword running_10-2[prototype.js]') ;// return this ;// }) ;// methods.checkName().checkEmail().checkPassword() ;/** * 形式十一-1(prototype.js): */Function.prototype.addMethods = function(name, fn){ this.prototype[name] = fn ; return this ;} ;var Methods = function() {} ;Methods.addMethods('checkName', function() { console.log('checkName running_11-1[prototype.js]') ; return this ;}).addMethods('checkEmail', function() { console.log('checkEmail running_11-1[prototype.js]') ; return this ;}).addMethods('checkPassword', function() { console.log('checkPassword running_11-1[prototype.js]') ; return this ;}) ;var m = new Methods() ;m.checkName().checkEmail().checkPassword() ;</script></body>
阅读全文
0 0
- 设计模式知识连载(1)---函数的书写方式
- 设计模式知识连载(12)---调用方式:多态
- 设计模式知识连载(6)---继承_2:创建即继承-构造函数继承
- 设计模式知识连载(13)---简单工厂模式:
- 设计模式知识连载(14)---工厂方法模式:
- 设计模式知识连载(15)---抽象工厂模式:
- 设计模式知识连载(16)---建造者模式:
- 设计模式知识连载(17)---原型模式:
- 设计模式知识连载(18)---单例模式:
- 设计模式知识连载(19)---外观模式:
- 设计模式知识连载(20)---适配器模式:
- 设计模式知识连载(21)---代理模式:
- 设计模式知识连载(22)---装饰者模式:
- 设计模式知识连载(23)---桥接模式:
- 设计模式知识连载(24)---组合模式:
- 设计模式知识连载(25)---享元模式:
- 设计模式知识连载(26)---模板方法模式:
- 设计模式知识连载(27)---观察者模式:
- python常用函数
- 学习Maven日记-3
- mysql用法
- 干货|开放数据集
- 循环神经网络(RNN, Recurrent Neural Networks)介绍
- 设计模式知识连载(1)---函数的书写方式
- 2017年书单
- Pandas DataFrame——按行构建
- 35年编程史沉淀下来的8条宝贵经验
- Hadoop入门之HDFS
- Html5中标签(包括新增常用)
- Android recyclerView的应用
- Picasso 加载网络图片
- oracle,split 分区 sql