2009/7/16 ColinFine <[email protected]>
>
>
> I'm not quite sure what you are asking.
> Inside a function 'this' always refers to the global object (the
> window) unless you have taken steps to make it refer to something
> else. A common way to make it refer to something else is by calling
> the function as a method (your 'itemManager.createHTML()'). Prototype
> provides another way in Function.bind.
>
> So if you use ItemManager.createHTML(), inside 'createHTML', 'this'
> will refer to ItemManager. But as far as I can see, you are not using
> 'this' inside 'createHTML' anyway, so the question is irrelevant.
>
>
Let's look at the method checkAll in Contact object:
var Contact = {
initialize: function(json,id_contact){
$('check-all').observe('click',this.checkAll.bindAsEventListener(this));
},
checkAll: function(e) {
e.stop();
this.contactChecked = [];
$$('#contacts-ul .contact-checkbox').each(function(c){
c.checked = true;
Contact.contactChecked.push(parseInt(c.value));
Here 'this' is a window object so I could use bind(this) and then use
this.contactChecked,
but I can skip bind and use Contact.contactChecked which I often do.
I would like to know how you deal with such situation, because I would use
bind as rarely as possible, that's all.
});
}
--
keemor
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---