i would go to not aliasing the "this" variable unless you want a closure to 
have access to the original this, like when passing a function to an event 
handler
other than that it seems that you are making up a generalization based on fear.

On Mar 5, 2011, at 10:47 AM, Michael Haufe (TNO) wrote:

> An alternative is not to write code that way to begin with so there
> won't be an issue with shadowing and extraneous function objects:
> 
> function Dialog(width){
>    this._width = width;
> }
> Dialog.prototype = {
>    constructor : Dialog,
>    setWidth : function(width){
>        this._width = width;
>    }
> }
> 
> On Mar 3, 1:08 pm, Jarek Foksa <[email protected]> wrote:
>> Hi,
>> 
>> When writing constructor functions it's very convenient to create "var
>> self = this" assignment so that we could easily access other
>> properties and methods even if default context has changed, for
>> example:
>> 
>> var Dialog = function() {
>>   var self = this;
>>   this.width = 400;
>>   this.setWidth = function(newWidth) {
>>     self.width = newWidth;
>>   }
>> 
>> }
>> 
>> But is it really a good idea to use "self" variable name for this
>> purpose? It seems to be already assigned to window object by default,
>> so I guess redefining it might break some third-party code.
>> 
>> What other names would you recommend? Is there some other convention?
> 
> -- 
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
> 
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
> 
> To unsubscribe from this group, send email to
> [email protected]

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to