当前位置: 首页 > 图文教程 > 网络编程 > Javascript > In Javascript Class, how to call the prototype method.(three method)

Javascript
DOM相关内容速查手册
[转]JS宝典学习笔记
背景,文字渐变(无闪屏)
一个仿DOS的Loading效果
JavaScript使用prototype定义对象类型
如何用JS获取带“\”字符串的中间值?
如何识别上传前检测的图像是有效的方法
js模拟滤镜的图片渐显效果
如何用javascript去掉字符串里的所有空格
javascript如何判断数组内元素是否重复的方法集锦
控制打印时页眉角的代码
模仿Flash AS效果的导航菜单
页面自定义拖拽布局
js判断浏览器的比较全的代码
又一日历输入效果没考虑兼容性,IE通过
项目添加
[转]prototype 源码解读 超强推荐
JAVASCRIPT对象及属性
JavaScript解决Joseph问题
实例:用 JavaScript 来操作字符串(一些字符串函数)

In Javascript Class, how to call the prototype method.(three method)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 135 ::
收藏到网摘: n/a

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>