首頁 >web前端 >js教程 >In Javascript Class, how to call the prototype method.(three method)_javascript技巧

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

WBOY
WBOY原創
2016-05-16 19:21:311074瀏覽

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>

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn