How to translate js function 'this' ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Eno
Reply | Threaded
Open this post in threaded view
|

How to translate js function 'this' ?

Eno

I had codes from javascript/jquery to translate to amber smalltalk equivalent:
    $('.president').bind('mouseover click', function(){
	var loc = $(this).attr('rel');
	if (loc && loc.indexOf(',') > 0) {
    	    loc = loc.split(',');
	    $('.zoom').anythingZoomer( loc[0], loc[1] );

I'm doing this way:
'.president' asJQuery bind: 'mouseover click' with: [
| loc |
loc = this attr: 'rel'.
[ loc and: ( ( loc indexOf: ',' ) > 0) ] ifTrue: [
loc := loc split: ','.
'.zoom' asJQuery anythingZoomer: ( loc at: 0 ) with: ( loc at: 1 ) ].
^ false ].

but failed, the 'this' inside the callback function is not correct that should be the current tagbrush hovered,
changing to 'this' asJQuery or 'self asJQuery , are all the same failed.

How to solved? ( I could workaround it by coding indivisual onMouseover callbacks of each 'a' tagbrush).

thanks.





--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to translate js function 'this' ?

Herby Vojčík
It is impossible to get to true this in amber block (inside method, it's self, of course). There is a transformation that allows you capture this, though:

  [ :thisarg :otherarg | ...code... ] currySelf

produces a block that does ...code... but the first argument (thisarg in the example) is not an argument any more, it just holds 'this'.

Herby

EnoX1 wrote:

>
> I had codes from javascript/jquery to translate to amber smalltalk
> equivalent:
>      $('.president').bind('mouseover click', function(){
> var loc = $(this).attr('rel');
> if (loc&&  loc.indexOf(',')>  0) {
>       loc = loc.split(',');
> $('.zoom').anythingZoomer( loc[0], loc[1] );
>
> I'm doing this way:
>      '.president' asJQuery bind: 'mouseover click' with: [
>            | loc |
> loc = this attr: 'rel'.
> [ loc and: ( ( loc indexOf: ',' )>  0) ] ifTrue: [
> loc := loc split: ','.
> '.zoom' asJQuery anythingZoomer: ( loc at: 0 ) with:  ( loc at: 1 ) ].
> ^ false ].
>
> but failed, the 'this' ins
ide the callback function is not correct that should be the current tagbrush hovered,

> changing to 'this' asJQuery or 'self asJQuery , are all the same failed.
>
> How to solved? ( I could workaround it by coding indivisual onMouseover callbacks of each 'a' tagbrush).
>
> thanks.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "amber-lang" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email].
> For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: How to translate js function 'this' ?

Manfred Kröhnert
Thanks Herby,

I just put this on the Amber wiki here:


Best,
Manfred




On Mon, Oct 21, 2013 at 2:00 PM, Herby Vojčík <[hidden email]> wrote:
It is impossible to get to true this in amber block (inside method, it's self, of course). There is a transformation that allows you capture this, though:

 [ :thisarg :otherarg | ...code... ] currySelf

produces a block that does ...code... but the first argument (thisarg in the example) is not an argument any more, it just holds 'this'.

Herby

EnoX1 wrote:

I had codes from javascript/jquery to translate to amber smalltalk equivalent:
     $('.president').bind('mouseover click', function(){
        var loc = $(this).attr('rel');
        if (loc&&  loc.indexOf(',')>  0) {

        loc = loc.split(',');
        $('.zoom').anythingZoomer( loc[0], loc[1] );

I'm doing this way:
     '.president' asJQuery bind: 'mouseover click' with: [
           | loc |
        loc = this attr: 'rel'.
        [ loc and: ( ( loc indexOf: ',' )>  0) ] ifTrue: [
                loc := loc split: ','.
        '.zoom' asJQuery anythingZoomer: ( loc at: 0 ) with:  ( loc at: 1 ) ].
        ^ false ].

but failed, the 'this' ins
ide the callback function is not correct that should be the current tagbrush hovered,
changing to 'this' asJQuery or 'self asJQuery , are all the same failed.

How to solved? ( I could workaround it by coding indivisual onMouseover callbacks of each 'a' tagbrush).

thanks.





--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "amber-lang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.