ok, so i have this function called doThis()i'm trying to attach it to an onclick event from within an instantiation of a prototype class and keep getting a "not defined" error or an "uncaught exception" error when i try to alert() instead.something like:
var iThing = document.createElement('div');iThing.id = "iThing";iThing.onclick = function(){doThis();};
var iThing = document.createElement('div');iThing.id = "iThing";iThing.onclick = "doThis();"var onClickHandler = new Function(iThing.onclick);if (iThing.addEventListener) { iThing.addEventListener('click', onClickHandler, false );} else if (iThing.attachEvent) { iThing.attachEvent('onclick', onClickHandler);} else { iThing.onclick = function(){doThis();};}
7/31/2007 8:59:21 AM
for the uncaught exception, attempt to catch it using a try/catchhttp://www.quackit.com/javascript/tutorial/javascript_try_catch.cfmand install firebughttp://addons.mozilla.org/firefox/addon/1843it'll help you get the JS right
7/31/2007 10:26:06 AM
yeah that doesn't really help
7/31/2007 1:50:16 PM
i guess what i'm asking is how do I reference a function declared outside of a class
function doThis() {alert('hi');}var AnObject = function (someVar){ this.Thing = someVar;}AnObject.prototype.annoy = function (){ doThis();}whatev = new AnObject(thingie);whatev.annoy();
7/31/2007 4:15:58 PM
I was bored and I threw your code into a file and it worked in firefox 2.0. I did have to change the assignment of whatev.
<html><head><script language="javascript">function doThis() {alert('hi');}var AnObject = function (someVar){ this.Thing = someVar;}AnObject.prototype.annoy = function (){ doThis();}whatev = new AnObject("test");whatev.annoy();</script></head><body><a href="#" onclick="whatev.annoy();">test</a></body></html>
7/31/2007 10:12:19 PM
i gave up, i think somewhere in all of my code i lost scope somewhere
8/1/2007 12:19:25 PM