In Javascript Class, how to call the prototype method.(three method)
更新時(shí)間:2007年01月09日 00:00:00 作者:
1、Using Javascript eval Method。
2、using a veriables save object "this" reference.
3、in innerHTML, we can using String to pass the prototype Method。
e.g.
<SCRIPT LANGUAGE="JavaScript">
<!--
function myClass(instanceName)
{
this.instanceName = instanceName;
this.instance = this;
return this;
};
myClass.prototype.toAlert=function()
{
eval(this.instanceName).callback(); // the first method to call prototype function.
this.instance.callback(); // the second method to call prototype function.
// the third method to call prototype function.
document.write("<a href='javascript:void(0);' onclick='" + this.instanceName + ".callback();'>instance call prototype function.</a>")
};
myClass.prototype.callback=function()
{
alert("blueDestiny, never-online");
};
var a = new myClass("a");
a.toAlert();
//-->
</SCRIPT>
2、using a veriables save object "this" reference.
3、in innerHTML, we can using String to pass the prototype Method。
e.g.
<SCRIPT LANGUAGE="JavaScript">
<!--
function myClass(instanceName)
{
this.instanceName = instanceName;
this.instance = this;
return this;
};
myClass.prototype.toAlert=function()
{
eval(this.instanceName).callback(); // the first method to call prototype function.
this.instance.callback(); // the second method to call prototype function.
// the third method to call prototype function.
document.write("<a href='javascript:void(0);' onclick='" + this.instanceName + ".callback();'>instance call prototype function.</a>")
};
myClass.prototype.callback=function()
{
alert("blueDestiny, never-online");
};
var a = new myClass("a");
a.toAlert();
//-->
</SCRIPT>
相關(guān)文章
如何使Chrome控制臺(tái)支持多行js模式——意外發(fā)現(xiàn)
一直以來(lái),Chrome控制臺(tái)都缺少象IE調(diào)試臺(tái)那樣的多行執(zhí)行模式,今天意外發(fā)現(xiàn)Chrome其實(shí)也支持多行模式2013-06-06javascript獲取本機(jī)操作系統(tǒng)類型的方法
關(guān)于我們使用電腦的操作系統(tǒng),我們通過(guò)鼠標(biāo)點(diǎn)擊就能獲取,如果我們想用腳本怎么實(shí)現(xiàn)javascript獲取本機(jī)操作系統(tǒng)類型的方法呢,下面給大家分享javascript獲取本機(jī)操作系統(tǒng)類型的方法,需要的朋友可以參考下2015-08-0825個(gè)讓你眼前一亮的JavaScript代碼技巧分享
學(xué)習(xí)強(qiáng)大的JavaScript一行代碼,能夠節(jié)省你的時(shí)間和代碼量,所以本文為大家整理了25個(gè)JavaScript實(shí)用代碼技巧,感興趣的小伙伴可以了解一下2023-07-07easyui關(guān)于validatebox實(shí)現(xiàn)多重規(guī)則驗(yàn)證的方法(必看)
下面小編就為大家?guī)?lái)一篇easyui關(guān)于validatebox實(shí)現(xiàn)多重規(guī)則驗(yàn)證的方法(必看)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04js解決event.keyCode在Firefox中失效的問(wèn)題
這篇文章主要介紹了js解決event.keyCode在Firefox中失效的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-12-12Javascript實(shí)現(xiàn)一朵從含苞到綻放的玫瑰
今天小編就為大家分享一篇關(guān)于Javascript實(shí)現(xiàn)一朵從含苞到綻放的玫瑰,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-03-03JavaScript同步與異步任務(wù)問(wèn)題詳解
這篇文章主要介紹了JavaScript事件循環(huán)同步任務(wù)與異步任務(wù),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下2022-07-07bootstrap滾動(dòng)監(jiān)控器使用方法解析
這篇文章主要為大家詳細(xì)解析了bootstrap滾動(dòng)監(jiān)控器使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-01-01