Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 19:21:31
Original
1047 people have browsed it

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> <BR><!-- <BR>function myClass(instanceName) <BR>{ <BR> this.instanceName = instanceName; <BR> this.instance = this; <BR> return this; <BR>}; <BR>myClass.prototype.toAlert=function() <BR>{ <BR> eval(this.instanceName).callback(); // the first method to call prototype function. <BR> this.instance.callback(); // the second method to call prototype function. <br><br> // the third method to call prototype function. <BR> document.write("<a href='javascript:void(0);' onclick='" + this.instanceName + ".callback();'>instance call prototype function.") <BR>}; <BR>myClass.prototype.callback=function() <BR>{ <BR> alert("blueDestiny, never-online"); <BR>}; <BR>var a = new myClass("a"); <BR>a.toAlert(); <BR>//--> <BR></script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template