[Javascript] Wolter Zorn's Drag and Drop Script

Roger Roelofs rer at datacompusa.com
Tue Aug 22 20:42:48 CDT 2006


Terry,

On Aug 22, 2006, at 3:32 PM, Terry Riegel wrote:

> I am working with a drag and drop library written by Walter Zorn. He 
> does some pretty cool things with his script. As I look at his code I 
> first realize that I don't really understand OOP.
Javascript OOP is a bit different than other languages, so it takes a 
while to understand it.

> I am trying to add a property to an object. Can anyone tell me why my 
> addition isn't working?
>
> dd.evt = function(d_e)
> {
> 	this.but = (this.e = d_e || window.event).which || this.e.button || 0;
> 	this.button = (this.e.type == 'mousedown')? this.but
> 		: (dd.e && dd.e.button)? dd.e.button
> 		: 0;
> 	this.src = this.e.target || this.e.srcElement || null;
> 	this.src.tag = ("" + (this.src.tagName || this.src)).toLowerCase();
> 	this.x = dd.Int(this.e.pageX || this.e.clientX || 0);
> 	this.y = dd.Int(this.e.pageY || this.e.clientY || 0);
>
> // My humble addition
> this.terryriegel = 723;
> // End my humble addition
>
>
> 	if(dd.ie)
> 	{
> 		this.x += dd.getScrollX() - (dd.ie && !dd.iemac)*1;
> 		this.y += dd.getScrollY() - (dd.ie && !dd.iemac)*1;
> 	}
> 	this.modifKey = this.e.modifiers? this.e.modifiers&Event.SHIFT_MASK : 
> (this.e.shiftKey || false);
> };

Two questions.  What makes you think it isn't working?  Do you use 
this.terryriegel somewhere else in the code?  Also, 'this' in 
javascript isn't always what you expect.  The code you pasted looks 
like an event handler.  In this context, 'this' may well be the window 
object rather than dd.

This is one of those cases where a url would be especially helpful in 
debugging.

hth
-- 
Roger Roelofs
Datacomp Appraisal Services




More information about the Javascript mailing list