Re: Attach a class method to event handler



On May 30, 12:33 pm, Thomas 'PointedEars' Lahn <PointedE...@xxxxxx>
wrote:
Peter Michaux wrote:
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.
[...]
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.

You are overlooking something important, then.

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.

True. However, a good answer would at least provide an equivalent solution
to the presented problem (which was, without doubt, how to avoid closures).
Yours did not provide an equivalent solution. (Mine did provide a
equivalent solution, but maybe no solution to the OP's problem. Insofar
both of us might have failed to provide a good answer.)

using the `this' reference in a prototype method

There was no use of "this" in the original question.

My example shows that this does not matter. Literally.

I have trimmed the quote more so that you may see the point more easily.

I can see that you have done a very nice job at trimming the quotes.

Peter

[snip] <-- see how I trimmed your signature.

.


Quantcast