Ciao Nick!
> > Many thanks in advance...and sorry for my english ;)
Nessun problema, mi dà la possibilità di practicare il mio
italiano. ;-)
(For non-Italian speakers: it's the usual answer about preserving
`this`.)
Il problema è con il callback da Droppable:
> Droppables.add(elem, {accept: class,
> onDrop:
> function(dragged, dropped) {
>
> this.aggiungiGiocatore();
Dentro del callback, `this` non ha il guisto valore. Ci necessario
usare Function#bind[1] o un closure per questo:
Con Function#bind:
* * * *
makeDroppable: function(elem, class) {
Droppables.add(elem, {
accept: class,
onDrop: (function(dragged, dropped) {
this.aggiungiGiocatore();
}).bind(this)
});
},
* * * *
Con un closure:
* * * *
makeDroppable: function(elem, class) {
var self = this;
Droppables.add(elem, {
accept: class,
onDrop: function(dragged, dropped) {
self.aggiungiGiocatore();
}
});
},
* * * *
C'è di più qui (in inglese, mi dispiace):
http://blog.niftysnippets.org/2008/04/you-must-remember-this.html
(Devo practicare il mio italiano di piu, ho avuto usare Google per
trovare alcuni dei frasi e parole. :-( )
Spero che questo aiuta,
--
T.J. Crowder
tj / crowder software / com
www.crowdersoftware.com
On Sep 30, 5:51 pm, Nick <[email protected]> wrote:
> Hi all,
>
> I created the following class with prototype
>
> ---------------------------------------------------------------------------
> --------------------------------------------------------
>
> var gestioneFormazione = Class.create ({
>
> initialize: function(modulo, formazioneDrop){
>
> ...
>
> for (var i = 0; i < formazioneDrop.length; i++){
> ....
>
> this.makeDroppable(idDiv, class);
> }
>
> },
>
> makeDroppable: function(elem, class){
>
> Droppables.add(elem, {accept: class,
> onDrop:
> function(dragged, dropped) {
>
> this.aggiungiGiocatore();
>
> }
> }
> );
>
> },
>
> aggiungiGiocatore: function(eDrag, eDrop){
>
> .....
> },
>
> });
>
> ---------------------------------------------------------------------------
> --------------------------------------------------------
>
> Can you tell me why I can not to call the method
> "this.aggiungiGiocatore"
> (" this.aggiungiGiocatore is not a function") only inside "onDrop"?
>
> Many thanks in advance...and sorry for my english ;)
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---