How to call a function using object prototype in Javascript -
i had doubt.is possible call 1 function/method present inside 1 class using object prototype in javascript ? if possible can make below code correct.
(function(){ window.peer=function(){ var peer=this; peer.getmessage=function(){ alert("hello!!! site.") } } })(); <button type="button" id="btn">click here</button> <script> document.getelementbyid('btn').onclick=function(){ peer.prototype.getmessage(); }
the above code throwing error.please give me idea resolve this.
(function(){ window.peer=function(){} window.peer.prototype.getmessage=function(){ alert("hello!!! site.") } })(); <button type="button" id="btn">click here</button> document.getelementbyid('btn').onclick=function(){ var peer = new peer(); peer.getmessage(); }
you can treat peer object
Comments
Post a Comment