PDA

View Full Version : this.prototype.addEvent doesn't work


BarrMan
11-20-2007, 01:15 AM
Hi.
I'm trying to make an addEvent function that will automatically attach itself to the object using a class.

My question is how can I add the function so when I write obj.addEvent("click",myfunction); it will add the event?

Here's my current function:
this.prototype.addEvent = function(type,fn)
{
if(window.attachEvent)
this.attachEvent("on"+type,fn);
else if(window.addEventListener)
this.addEventListener(type,fn,false);
}


Thanks.

BarrMan
11-20-2007, 01:31 AM
Also, I have another question.

I'm working on creating a calendar now and I'm doing it using classes but I have a problem when I add an event to an object I create during the class creation:
this.prototype._refresh()
{
addEvent(obj,this.incMonth());
}

When I do something like that it says that it doesn't recognize the function incMonth. And the reason is because it refers the current object and not to the class.

My question is: How can I make it refer to the class and not the object?

Thanks.

BarrMan
11-20-2007, 02:28 AM
Problem number 2 is solved.

A1ien51
11-20-2007, 03:21 AM
1) Object.prototype.addEvent

2) () was the issue


Eric

kiflea1
05-28-2008, 08:02 PM
var obj = this

addListener(element, eventtype, function(e){obj.method(e);});
something like that