1、javascript靈活語言
方式一、
function checkName() { } function checkEmail()) { } function checkPassword() { }
方式二、
var checkName=function(){} var checkEmail=function(){} var checkPasswork=function(){}
方式1一和方式二都是全域性作用域變數,方式二能直觀說名在javascript中函式也是變數,只是定義時位置不同而已
2、用物件收編變數
方式一、
var checkObject={ checkName:function(){}, checkEmail:function(){}, checkPassword:function(){} }
方式二、
var checkObject = function () { } checkObject.checkName = function () { return this; } checkObject.checkEmail = function () { return this; } checkObject.checkPassword = function () { return this; }
3、真假物件
var checkObject = function () { return { checkName: function () { }, checkEmail: function () { }, checkPassword: function () { } } }
var obj= checkObject();
obj.checkName();
4、類形式
var checkObject = function () { this.checkName = function () { }; this.checkEmail = function(){ }; this.checkPassword = function(){ }; } var obj = new checkObject(); obj.checkName();
5、原型形式
方式一、
var checkObject = function () { } checkObject.checkName = function () { } checkObject.checkEmail = function () { } checkObject.checkPassword = function(){ }
方式二、
var checkObject = function () { return { checkName: function () { }, checkEmail: function () { }, checkPassword: function () { } } }
6、原型形式加 Return
var checkObject = function () { } checkObject.checkName = function () { return this; } checkObject.checkEmail = function () { return this; } checkObject.checkPassword = function(){ return this; }
方式二、
var checkObject = function () { return { checkName: function () { return this; }, checkEmail: function () { return this; }, checkPassword: function () { return this; } } }