看看這不到壹百行代碼
妳會學到很多的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
//--------------------------------------//
//演示函數用法,typeof運算符,for in 用法,數組的內建方法push,pop
function showWindowObj(){
var ary = [];
if(typeof(window) == 'undefined'){
return ;
}
for (var x in window){
ary.push([x ,eval("window." + x)])
}
alert(ary.length);
var record = ary.pop();
ary.push(record);
return ary;
}
alert(showWindowObj().length);
//--------------------------------------//
//演示閉包,for 循環;
(function (){
var arg = [];
for (var i = 0 , j = arguments.length ; i < j ; i++){
arg.push(arguments[i]);
}
alert(arg.join(","));
})('string1','string2');
//--------------------------------------//
//演示原型方法的創建,正則表達式;
String.prototype.trim = function (){
return this.replace( /^\s+|\s+$/g, "" );
}
var str = " a string " , str_trimd;
str_trimd = str.trim();
alert("length of +" + str + " : " + str.length);
alert("length of +" + str_trimd + " : " + str_trimd.length);
//--------------------------------------//
// 演示模擬類的實現,
function Person(name,gender){
this.name = name;
this.gender = gender;
//實例方法
this.sayHello = function (){
alert("hello");
}
}
//類靜態方法
Person.prototype = {
showName : function (){
alert(this.name);
}
,showGender : function (){
alert(this.gender);
}
}
var me = new Person ('myname','male');
me.sayHello();
me.showName();
me.showGender();
//-->
</SCRIPT>
</BODY>
</HTML>