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

2016-02-19 10:55 2 1 收藏

下面图老师小编跟大家分享一个简单易学的In Javascript Class, how to call the prototype method.(three method)教程,get新技能是需要行动的,喜欢的朋友赶紧收藏起来学习下吧!

【 tulaoshi.com - Web开发 】

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

来源:https://www.tulaoshi.com/n/20160219/1596090.html

延伸阅读
标签: Web开发
Form: http://www.webreference.com/programming/javascript/mk/ Author:Mark Kahn Many developers have a large library of JavaScript code at their fingertips that they developed, their collegues developed, or that&nb...
标签: Web开发
open Method Assigns method, destination URL, and other optional attributes of a pending request. Syntax XMLHttpRequest .open( sMethod , sUrl [ , bAsync ] [ , sUser ] [ , sPassword ] ) [/pre] Parameters sMethod Required. String that specifies the HTTP method used to open the connection: suc...
标签: Web开发
昨天阿丹传了一个javascript中的重载例子给我,感觉不错.虽然到现在还是不太明白.怎么实现的.但还是贴出来. 实现setTimeout传object对象 看以下代码实现向里面的function 传参数 script type="text/javascript" var _st = window.setTimeout; window.setTimeout = function(fRef, mDelay) { ...
标签: Web开发
From: JavaEye.com prototype提供了一套JavaScript面向对象基础设施,我们可以使用它来进行面向对象编程,定义对象类型方式如下:  var Person = Class.create(); Person.prototype = {  initialize : function(name, age) {  this.name = na...
标签: Web开发
javaScript 中的 call() 是一个奇妙的方法,但也是一个让人迷惑的方法,先看一下官方的解释: call 方法 应用于:Function 对象 要求: 版本 5.5 调用一个对象的一个方法,以另一个对象替换当前对象。 参数 thisObj 可选项。将被用作当前对象的对象。 arg1, arg2, , argN 可选项。将被传递方法参数序列。 说明: c...

经验教程

151

收藏

20

精华推荐

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部