Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Using .bind(this)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
VirtuosiMedia  
View profile  
 More options Aug 26 2008, 4:51 pm
From: VirtuosiMedia <cont...@virtuosimedia.com>
Date: Tue, 26 Aug 2008 13:51:31 -0700 (PDT)
Local: Tues, Aug 26 2008 4:51 pm
Subject: Using .bind(this)
Could anyone explain to me in what situations 'this' should be bound
and perhaps provide a few examples? I keep running into problems in
writing classes and I think that my lack of understanding of when and
how to use it is one of the major difficulties. I've looked at the
documentation in the mootorial and in the docs section, but the
explanations on binding are cursory at best. Any help would really be
appreciated. Thanks.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
tr0y  
View profile  
 More options Aug 26 2008, 5:27 pm
From: tr0y <wolfest...@gmail.com>
Date: Tue, 26 Aug 2008 14:27:02 -0700 (PDT)
Local: Tues, Aug 26 2008 5:27 pm
Subject: Re: Using .bind(this)
As I understand it, .bind lets you pass a variable to the bound
function, making the "this" within the function refer to the bound
variable...

$('netTween_set').addEvent('click', newTweenSet.bind(newTween));

In this case, newTween is the tween object and newTweenSet is the
function.

Now, inside the function newTweenSet, using "this" will refer to
newTween, letting you write something like this:

var newTweenSet = function() {
        this.start('width', '300px');

}

Hope this answers your question.

On Aug 26, 1:51 pm, VirtuosiMedia <cont...@virtuosimedia.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
VirtuosiMedia  
View profile  
 More options Aug 26 2008, 5:47 pm
From: VirtuosiMedia <cont...@virtuosimedia.com>
Date: Tue, 26 Aug 2008 14:47:02 -0700 (PDT)
Local: Tues, Aug 26 2008 5:47 pm
Subject: Re: Using .bind(this)
So just to clarify, binding will cause the scope for this to refer to
the current function rather than the global space?

On Aug 26, 2:27 pm, tr0y <wolfest...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
virtualgadjo  
View profile  
 More options Aug 27 2008, 11:38 am
From: virtualgadjo <virtualga...@gmail.com>
Date: Wed, 27 Aug 2008 08:38:38 -0700 (PDT)
Local: Wed, Aug 27 2008 11:38 am
Subject: Re: Using .bind(this)
hi,

just a word because i think the question could concern the bind usage
inside a class
a little example, a very, very useful class :)))
#############"
var toto = new Class ({

        Implements: Options,

        options: {
                message: "toto"
        },

        initialize: function(elem, options){
                this.setOptions(options);
                this.alternateMessage = "a message";
                this.elem = elem;
                this.elem.addEvent('click', function(){
                        this.alternateMessage = "other message";
                        this.aMethod();
                }.bind(this));
        },

        aMethod: function(){
                alert(this.options.message);
        }

});

##################
in this class, you can see two effects of this binding in this
function

this.elem.addEvent('click', function(){
    this.alternateMessage = "other message";
    this.aMethod();

}.bind(this));

- this.alternateMessage is now changed for the whole class, not only
inside the fucntion as this refers to the class
- without binding the click function with .bind(this) the result would
be "this.alternateMessage has no properties", "this.aMethod() is not a
function"
binding the function to the class (this) allows it to use any method
or this.var set inside it

hope it'll help

have swing


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
VirtuosiMedia  
View profile  
 More options Aug 27 2008, 2:58 pm
From: VirtuosiMedia <cont...@virtuosimedia.com>
Date: Wed, 27 Aug 2008 11:58:25 -0700 (PDT)
Local: Wed, Aug 27 2008 2:58 pm
Subject: Re: Using .bind(this)
That example helped a lot. Thank you very much.

On Aug 27, 8:38 am, virtualgadjo <virtualga...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google