javascript面向?qū)ο缶幊?一) 實(shí)例代碼
更新時(shí)間:2010年06月25日 00:48:50 作者:
javascript面向?qū)ο缶幊虒?shí)例代碼,代碼也算比較基礎(chǔ)了,不懂得朋友可以參考腳本之家之前發(fā)布的文章。
復(fù)制代碼 代碼如下:
<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>
相關(guān)文章
面向?qū)ο蟮木幊趟枷朐趈avascript中的運(yùn)用上部
對于正在從事或者打算從事編程的人來說,面向?qū)ο笫且粋€(gè)耳熟能詳?shù)脑~,幾乎每一個(gè)人都能列舉出一些面向?qū)ο蟮木幊陶Z言,例如C++,JAVA,C#等等。2009-11-11
[推薦]javascript 面向?qū)ο蠹夹g(shù)基礎(chǔ)教程
看了很多介紹javascript面向?qū)ο蠹夹g(shù)的文章,很暈.為什么?不是因?yàn)閷懙貌缓?而是因?yàn)樘願(yuàn)W. javascript中的對象還沒解釋清楚怎么回事,一上來就直奔主題,類/繼承/原型/私有變量....2009-03-03
實(shí)現(xiàn)JavaScript中繼承的三種方式
在JavaScript中,繼承可以通過三種手法實(shí)現(xiàn)原型鏈繼承 使用apply、call方法 對象實(shí)例間的繼承。2009-10-10
用JavaScript實(shí)現(xiàn)單繼承和多繼承的簡單方法
JavaScript是一種強(qiáng)大的多泛型編程語言,其融合了面向過程、面向?qū)ο蠛秃瘮?shù)式編程于一身,具備強(qiáng)大的表現(xiàn)能力。2009-03-03

