iT邦幫忙

0

javacript筆記

紀錄
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 );
	}
}

// 測試2
introduce('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();

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言