[Proto-Scripty] Re: add more paramaters to call on a observe?

2009-05-30 Thread T.J. Crowder

Hi,

 Thanks T.J., with curry has enough

Aren't you using an object instance method?  Function#curry won't
preserve context (so if you use this within the method, it will
refer to the wrong object).

-- T.J. :-)

On May 30, 12:58 am, Miguel Beltran R. yourpa...@gmail.com wrote:
  (And again, if you didn't need context, you could use Function#curry
  [3] and the event would be the last parameter.)

 Thanks T.J., with curry has enough
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: add more paramaters to call on a observe?

2009-05-30 Thread Miguel Beltran R.

 Aren't you using an object instance method?  Function#curry won't
 preserve context (so if you use this within the method, it will
 refer to the wrong object).


For this case no need use this.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: add more paramaters to call on a observe?

2009-05-29 Thread T.J. Crowder

Hi Miquel,

You have a couple of choices:  Function#bind[1] (you could use
Function#curry if you didn't need context, but I see you do) or
Function#bindAsEventListener[2].  They basically come to the same
thing, it's just a matter of whether your function receives the event
parameter as the first or the last parameter.

Option 1:  Using Function#bind and making the event parameter your
last param:

$('myelement').observe('click', this.fooFunction.bind(this, 'a',
'b'));

fooFunction:  function(paramA, paramB, event) {
// ...
}

In this option, Function#bind does two things for you:  It binds
context (this), and it burns in (or curries) two parameters to
the function.  When the element is clicked, the function will be
called with paramA = 'a', paramB = 'b', and event = the event.
Parameters curried via Function#bind are always the first parameters
to the function.

Option 2:  Using Function#bindAsEventListener and making the event
parameter your first param:

$('myelement').observe('click', this.fooFunction.bindAsEventListener
(this, 'a', 'b'));

fooFunction:  function(event, paramA, paramB) {
// ...
}

Function#bindAsEventListener also binds context and curries
parametesr, but it always makes the event parameter the first
parameter to your function.  It's a special case.

(And again, if you didn't need context, you could use Function#curry
[3] and the event would be the last parameter.)

[1] http://prototypejs.org/api/function/bind
[2] http://prototypejs.org/api/function/bindAsEventListener
[3] http://prototypejs.org/api/function/curry

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On May 29, 12:12 am, Miguel Beltran R. yourpa...@gmail.com wrote:
 Hi list

 I have a function fooClass what i want convert for more generic.

 fooClass = Class.create()
 fooClass.addMethods({
    fooFunction: function(evt){
       //do stuff
    }

 });

 If change the function to fooFunction(evt, PARAM){}
 how must be the call?
 foo= new FooClass();
 someelement.observe('click', foo.fooFunction('apples'));
 otherelement.observe('click', foo.fooFunction('orange'));
 this is correct way?

 Thanks
 --
 
 Lo bueno de vivir un dia mas
 es saber que nos queda un dia menos de vida
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: add more paramaters to call on a observe?

2009-05-29 Thread Miguel Beltran R.



 (And again, if you didn't need context, you could use Function#curry
 [3] and the event would be the last parameter.)


Thanks T.J., with curry has enough

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---