javascript面向对象编程(一) 实例代码

 更新时间:2010年06月25日 00:48:50   作者:  
javascript面向对象编程实例代码,代码也算比较基础了,不懂得朋友可以参考脚本之家之前发布的文章。
复制代码 代码如下:

<script type="text/javascript">
var test = {
numA: 10,
objB: {},
arrC: [],
init: function(){
alert(this.numA);
},
sayHi: function(name){
alert("hello " + name);
},
sayHelloWorld: function(){
this.sayHi("world");
},
get: function(){
var self = this;
this.objB.alertNumA = function(){
alert(self.numA);
}
}
};
var TestFunc = function(){
alert("i'm testFunc");
};
TestFunc.prototype = {
extFunc: function(){
alert("this extend function's numB is " + this.numB);
},
numB: 10
};
test.init();
test.sayHi("qingming");
test.sayHelloWorld();
test.get();
test.objB.alertNumA();
var testFunc = new TestFunc();
testFunc.extFunc();
</script>

相关文章

最新评论