200点javascrapt代码
看看这不到100行的代码。
你会学到很多东西。
& lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " & gt;
& ltHTML & gt
& ltHEAD & gt
& ltTITLE & gt新文档& lt/TITLE & gt;
& ltMETA NAME = " Generator " CONTENT = " EditPlus " & gt;
& ltMETA NAME = " Author " CONTENT = " " & gt;
& ltMETA NAME = " Keywords " CONTENT = " " & gt;
& ltMETA NAME = " Description " CONTENT = " " & gt;
& lt/HEAD & gt;
& ltBODY & gt
& lt脚本语言= " JavaScript " & gt
& lt!-
// - //
//演示函数用法,运算符的类型,for in用法,数组push的内置方法,pop。
函数showWindowObj(){
var ary =[];
if(type of(window)= = ' undefined '){
返回;
}
for(窗口中的变量x){
ary.push([x,eval("window。"+ x)])
}
alert(ary . length);
var record = ary . pop();
ary.push(记录);
返回ary
}
alert(showWindowObj()。长度);
// - //
//演示闭包,for循环;
(函数(){
var arg =[];
for (var i = 0,j = arguments.length我& ltj;i++){
arg . push(arguments[I]);
}
alert(arg.join(",");
})('string1 ',' string 2 ');
// - //
//演示原型方法和正则表达式的创建;
string . prototype . trim = function(){
return this . replace(/^\s+|\s+$/g," ");
}
var str = " a string ",str _ trimd
str _ trimd = str . trim();
alert("长度+"+str+":"+str . length);
alert(" length of+"+str _ trimd+":"+str _ trimd . length);
// - //
//演示模拟类的实现。
职能人员(姓名,性别){
this.name = name
this.gender =性别;
//实例方法
this.sayHello = function (){
alert(“你好”);
}
}
//类静态方法
Person.prototype = {
showName : function (){
alert(this . name);
}
,showGender : function (){
alert(this . gender);
}
}
var me =新人('我的名字','男性');
me . say hello();
me . showname();
me . show gender();
//-& gt;
& lt/SCRIPT & gt;
& lt/BODY & gt;
& lt/HTML & gt;