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)文章
解析element-ui中upload組件傳遞文件及其他參數(shù)的問(wèn)題
這篇文章主要介紹了element-ui中upload組件如何傳遞文件及其他參數(shù),分析一下我使用element-ui遇到的問(wèn)題以及解決方法,需要的朋友可以參考下2021-11-11
javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)的方法
這篇文章主要介紹了javascript獲取當(dāng)前鼠標(biāo)坐標(biāo)的方法,可針對(duì)不同瀏覽器獲取鼠標(biāo)的坐標(biāo)位置,是非常實(shí)用技巧,需要的朋友可以參考下2015-01-01
js實(shí)現(xiàn)用戶(hù)注冊(cè)協(xié)議倒計(jì)時(shí)的方法
這篇文章主要介紹了js實(shí)現(xiàn)用戶(hù)注冊(cè)協(xié)議倒計(jì)時(shí)的方法,是開(kāi)發(fā)會(huì)員注冊(cè)功能時(shí)非常實(shí)用的技巧,需要的朋友可以參考下2015-01-01
layui監(jiān)聽(tīng)工具欄的實(shí)例(操作列表按鈕)
今天小編就為大家分享一篇layui監(jiān)聽(tīng)工具欄的實(shí)例(操作列表按鈕),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
JavaScript中var let const的用法有哪些區(qū)別
在ES6(ES2015)出現(xiàn)之前,JavaScript中聲明變量就只有通過(guò)var關(guān)鍵字,函數(shù)聲明是通過(guò)function關(guān)鍵字,而在ES6之后,聲明的方式有var、let、const、function、class,本文主要討論var、let和const之間的區(qū)別2021-10-10
ECharts坐標(biāo)軸刻度數(shù)值處理方法例子
這篇文章主要給大家介紹了關(guān)于ECharts坐標(biāo)軸刻度數(shù)值處理的相關(guān)資料,文章介紹了一個(gè)用于圖表Y軸數(shù)值簡(jiǎn)寫(xiě)的函數(shù),它可以將大數(shù)值轉(zhuǎn)換為K、M、B等簡(jiǎn)寫(xiě)形式,從而使圖表更加美觀和易讀,需要的朋友可以參考下2024-11-11
JavaScript判斷兩個(gè)對(duì)象是否相等的方法總結(jié)
判斷兩個(gè)對(duì)象是否相等是js中的一個(gè)很常見(jiàn)的內(nèi)容,不同的編程語(yǔ)言和環(huán)境可能會(huì)有不同的方式來(lái)實(shí)現(xiàn)這一目標(biāo),在 JavaScript 中,判斷兩個(gè)對(duì)象是否相等主要有以下幾種方法,感興趣的小伙伴跟著小編一起來(lái)看看吧2024-08-08

