Re: Attach a class method to event handler
- From: Peter Michaux <petermichaux@xxxxxxxxx>
- Date: Fri, 30 May 2008 10:05:31 -0700 (PDT)
On May 30, 4:43 am, Thomas 'PointedEars' Lahn <PointedE...@xxxxxx>
wrote:
Peter Michaux wrote:
On May 29, 5:35 pm, Thomas 'PointedEars' Lahn <PointedE...@xxxxxx>
wrote:
Peter Michaux wrote:
[...]
MyClass.prototype.doSomething = function( ) {};
MyClass.prototype.assignFun = function( )
{
document.getElementById('my_div').onclick = function ( e )
{
MyClass.prototype.doSomethingWith( e || event );
}
}
While this is not the least equivalent to the original, `MyClass' is the
bound "variable" of the closure then.
or perhaps even
MyClass.prototype.doSomething = function( ) {};It is getting worse. Now the method of the prototype object will be called
MyClass.prototype.assignFun = function( )
{
document.getElementById('my_div').onclick =
MyClass.prototype.doSomethingWith;
}
as a method of the Global Object.
It wasn't clear what the code in the original post was doing or even
if the doSomething function uses "this". Without a complete question a
complete answer is not possible.
You are winding around the issue.
No I'm not.
It does not matter whether the purpose of the code was clear (to you) or
not;
If the question is not clear then many answers are possible.
using the `this' reference in a prototype method
There was no use of "this" in the original question.
and using the
reference to the prototype object there are clearly not the same thing, nor
are assigning the reference to a prototype method versus assigning a
reference to a Function object that calls this prototype method (as
inherited through the prototype chain). So it cannot be expected to have
the same outcome, and is therefore not the least equivalent to one another.
But it may have acceptable outcome. The question was not clear. That
was actually one point I was making with my original answer.
[snip]
Peter
.
- Follow-Ups:
- Re: Attach a class method to event handler
- From: Thomas 'PointedEars' Lahn
- Re: Attach a class method to event handler
- References:
- Attach a class method to event handler
- From: Ugo
- Re: Attach a class method to event handler
- From: Peter Michaux
- Re: Attach a class method to event handler
- From: Thomas 'PointedEars' Lahn
- Re: Attach a class method to event handler
- From: Peter Michaux
- Re: Attach a class method to event handler
- From: Thomas 'PointedEars' Lahn
- Attach a class method to event handler
- Prev by Date: Re: Replacing document.getElementById with $ (dollar sign)
- Next by Date: Re: Lots of noise about user agent strings
- Previous by thread: Re: Attach a class method to event handler
- Next by thread: Re: Attach a class method to event handler
- Index(es):
Relevant Pages
|