RE: Event binding/this problem

Arjen Geerse <[email protected]>
Newsgroups gmane.comp.web.dom.wdf
Message-ID <302E6CBDF25DD511B74600508BB36D480964A252@mailbox1.amsterdam.lostboys.com>
Hi Seb,

This is because setTimeout runs in the global context. In that context,
"this" refers to the window object.

You can circumvent that from happening by using a closure:

function ... () {


	node.onmouseout = function () {
		var domelement = node;
		setTimeout(function () {rollout(domelement)}, 500);
	}


}

function rollout (DOMElement) {
	DOMElement.className=DOMElement.className.replace(" over", "");
}

Hope this helps,

Arjen

PS underlying theory can be found at
http://jibbering.com/faq/faq_notes/closures.html


-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf
Of Seb Frost
Sent: woensdag 9 november 2005 15:38
To: [email protected]
Subject: [wdf-dom] Event binding/this problem


function rollout()
{
	var temp= function() { this.className=this.className.replace("
over",
"");};

	setTimeout(temp,500);
}

node.onmouseout  = rollout;


gives me "this.className is null or not an object".




I've tried about a million variations on the above and can't get anything to
do what I want, I know it's some problem with passing the this reference
around, but don't know how to fix it.

Please help!




Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links



 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/9rHolB/TM
--------------------------------------------------------------------~-> 

Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.