纪录function log(msg) {if( window.console ) {console.log(msg);}}多载function introduce() {var callback = null;var msg = '';for( var i=0; i<arguments.length; i++ ) {var p = arguments[i];if( typeof p == 'string' ) {msg += p;} else if( typeof p == 'number' ) {msg += p;} else if( typeof p == 'function' ) {callback = p;}}if( callback != null ) {callback(msg);} else {log( msg );}}// 测试2introduce('David'); // introduce('David', 29); // introduce('David', function(msg) { // alert(msg);});introduce('David', 29, function(msg) { //alert(msg);});//点击document.getElementById('Form').onclick = function() { alert(Verificat.Form());};
// 先定义要用到的变量var a = 1, b = 0 , c = “";/* 写法一 */// 简写:a && (c += “OK");// 正写:if (a) {c += “OK";}/* 写法二 */// 简写:b || (b = 2);// 正写:if (!b) {b = 2;}/* 写法三 */// 简写:a ? ( (c = “yes"), (b = 1) ) : ( (c = “no"), (b = 2) );// 正写if (a) {c = “yes";b = 1;}else{c = “no";b = 2;}/* 写法四 */// 简写 (1):(a == window.getElementById(“c")) && (a.style.display = “none");// 简写 (2):(a == window.getElementById(“c")) ? a.style.display = “none" : “";// 正写:if (a == window.getElementById(“c")) {a.style.display = “none";}/* 写法五 */// 简写return a.nodeType != 3? a.tagName: a.setIntval? “window": “other"// 正写if (a.nodeType != 3) {return a.tageName;}else if (a.setIntval) {return “window";}else{return “other";}
function Fish(iColor,iSize,iType) {// 因为 this 容易产生误解,所以指定为 oComponent MyObj=this;MyObj.color = iColor;MyObj.Size = iSize;MyObj.Type = iType;//下面这样的宣告模式跟Public 的意思是一样的。MyObj.showColor = function() {alert(这条的鱼的颜色是 ' + MyObj.color);};//这样的宣告模式..就跟private是一样的var showSize= function(sMethod,sParameters){alert(这条的鱼的的类型 ' + MyObj.Type);};};var Fish1 = new Fish('red', 4, '淡水');var Fish2 = new Fish('blue', 3, '海水');Fish1.showColor();//这行是会有错误的Fish2.showSize();