js技巧--创建class时调用prototype原型方法
2010-12-10 19:51
316 查看
一般情况下有三种方法:
1、用eval方法。
2、先把this的引用传递给一个变量。
3、在创建HTML里可以直接用instance的字符串。
更详细的请看示例。
<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>
1、用eval方法。
2、先把this的引用传递给一个变量。
3、在创建HTML里可以直接用instance的字符串。
更详细的请看示例。
<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>
相关文章推荐
- js原型链继承及调用父类方法
- js入门实例の构造函数\方法的定义和调用\原型对象
- [js高手之路]原型对象(prototype)与原型链相关属性与方法详解
- SilverLight 页面后台方法XX.xaml.cs 创建JS,调用JS ,弹出提示框
- js中匿名函数的创建与调用方法分析
- js利用prototype调用Array的slice方法示例
- js的原型实例prototype--方法--属性,构造,赋值--方法同样有原型--原型含义
- JS面向对象(2) -- this的使用,对象之间的赋值,for...in语句,delete使用,成员方法,json对象的使用,prototype的使用,原型继承与原型链
- 创建Bean的三种方式 在大多数情况下,Spring容器直接通过new关键字调用构造器来创建Bean实例,而class属性指定Bean实例的实现类,但这不是实例化Bean的唯一方法。实际上,Sprin
- 详解JS构造函数方法与原型prototype上的方法
- js利用prototype调用Array的slice方法
- JS在子类中用Object.getPrototypeOf去调用父类方法
- js创建调用ocx对象的几种方法,检测ocx是否可用
- JS_创建对象+调用对象方法
- js中匿名函数的创建和调用方法分析
- JS中定义对象方式四: 使用原型(prototype)方式创建对象之一
- JS常见创建类的方法小结【工厂方式,构造器方式,原型方式,联合方式等】
- js入门实例の构造函数\方法的定义和调用\原型对象
- C#使用技巧之调用JS脚本方法一
- js对象中原型(prototype)的使用方法、替换以及注意事项