现在进入了WEB2.0时代,AJAX的应用也将无处不在,紧随其后的ajax ToolKit也相继出现DOJO、YahooUI...等非常强大的面向对象的JavaScript的工具箱,
对于你方便阅读Source,最好能够了解一下JavaScript下如何使用OO进行编程的, 这有很大的用处,以下偶提供的小例讲述了JS OO编程的简单应用
[code]<html>
<head>
<title></title>
<script>
function ClassTest1(){
alert("Congratulation! this frist class build success!");
}
function aa(){
var a=new ClassTest1();
}
function ClassTest2(var1){
alert(var1);
}
var b=new ClassTest2("hello");
//构建一个class并构造一个name属性
function ClassTest3(name){
this.name = name;
}
/*ClassTest3的成员方法*/
ClassTest3.prototype.sayHello = function () {
alert("Hello " + this.name);
}
function newClassTest3(){
//实例化类class3
var class3 = new ClassTest3("class3name");
class3.sayHello();
//创建一个age属性并对其付值
class3.age = 1;
alert(class3.age);
/*创建一个address.home属性并对其付值(与许多
面对象的语言一样JS也可以像用‘.’一样来用‘[]’来引用来
属性,主要是为了避免带'.'的属性)*/
class3['address.home'] = "shijiazhuang";
alert(class3['address.home']);
}
</script>
<script language="javascript" type="text/javascript">
//我们可以通过for in循环来遍历对象的属性。
var testObj = {
prop1 : "hello",
prop2 : "hello2",
prop3 : new Array("hello",1,2)
}
for(x in testObj) alert( x + "-" + testObj[ x ] )
//-->
</script>
<SCRIPT LANGUAGE="javascript">
<!--
var Circle = { x : 0, y : 1, radius: 2 } // another example
for(p in Circle)
alert( p + "-" + Circle[ p ] )
</SCRIPT>
</head>
<body>
<input type="button" onclick="aa()"/>
<input type="button" onclick="newClassTest3()"/>
</body>
</html>[/code]
对于你方便阅读Source,最好能够了解一下JavaScript下如何使用OO进行编程的, 这有很大的用处,以下偶提供的小例讲述了JS OO编程的简单应用
[code]<html>
<head>
<title></title>
<script>
function ClassTest1(){
alert("Congratulation! this frist class build success!");
}
function aa(){
var a=new ClassTest1();
}
function ClassTest2(var1){
alert(var1);
}
var b=new ClassTest2("hello");
//构建一个class并构造一个name属性
function ClassTest3(name){
this.name = name;
}
/*ClassTest3的成员方法*/
ClassTest3.prototype.sayHello = function () {
alert("Hello " + this.name);
}
function newClassTest3(){
//实例化类class3
var class3 = new ClassTest3("class3name");
class3.sayHello();
//创建一个age属性并对其付值
class3.age = 1;
alert(class3.age);
/*创建一个address.home属性并对其付值(与许多
面对象的语言一样JS也可以像用‘.’一样来用‘[]’来引用来
属性,主要是为了避免带'.'的属性)*/
class3['address.home'] = "shijiazhuang";
alert(class3['address.home']);
}
</script>
<script language="javascript" type="text/javascript">
//我们可以通过for in循环来遍历对象的属性。
var testObj = {
prop1 : "hello",
prop2 : "hello2",
prop3 : new Array("hello",1,2)
}
for(x in testObj) alert( x + "-" + testObj[ x ] )
//-->
</script>
<SCRIPT LANGUAGE="javascript">
<!--
var Circle = { x : 0, y : 1, radius: 2 } // another example
for(p in Circle)
alert( p + "-" + Circle[ p ] )
</SCRIPT>
</head>
<body>
<input type="button" onclick="aa()"/>
<input type="button" onclick="newClassTest3()"/>
</body>
</html>[/code]