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: Orlando Vazquez <ovazq...@gmail.com>
Date: Tue, 26 Oct 2010 17:32:25 -0700
Local: Tues, Oct 26 2010 8:32 pm
Subject: Re: [nodejs] what is var self = this; ?
On Tue, Oct 26, 2010 at 4:03 PM, Dominic Tarr <dominic.t...@gmail.com> wrote: Someone please correct me if I'm wrong, but JavaScript only has > what is the purpose of > self = this > I've seen it a bunch of times now, but not 100% sure what it's for. > is it so that functions in a object retain access to the object's > prototype/instance and would 'this' point to the prototype object of a > function if it is not initialized with new? function scope and global scope. If a variable is not found in the current scope, JavaScript keeps going up in scopes until it finds that variable or decides it doesn't exist. This is the case for most variables, with the exception of `this` and `arguments`, which ALL functions get. (There may be more, but I dont remember offhand) Typically `this` can come from an instantiated object that's had a method called on it, or someone doing a Fn.apply or Fn.call with an explicit target object. (eg myfunction.apply(myobject, args) => this = myobject) Therefore, in order to "hold onto" a previous scope, we just assign it -- 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.
| ||||||||||||||