2009/7/16 ColinFine <colin.f...@pace.com>

> 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){

    checkAll: function(e) {
        this.contactChecked = [];

        $$('#contacts-ul .contact-checkbox').each(function(c){
                c.checked = true;

Here 'this' is a window object so I could use bind(this) and then use
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.



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 
For more options, visit this group at 

Reply via email to