Personally, I prefer returning a new object for object creation.

var Dialog = function(){
 var width = 400
    , setWidth = function(newWidth){
         width = newWidth;
    };
  return {
     width: width
   , setWidth: setWidth
   };
}

Take a look at these two articles by Agnus Croll about creating
objects: 
http://javascriptweblog.wordpress.com/2010/03/16/five-ways-to-create-objects/
and 
http://javascriptweblog.wordpress.com/2010/03/16/five-ways-to-create-obejcts-part-2-inheritance/

As for using the name self, there's no problem because of closures.
However, if you want access to window's self, you won't be able to use
that. Another popular name is `that'.
------------------------
Gary Katsevman
Computer Science Undergraduate
Northeastern University
gkatsev.com



On Thu, Mar 3, 2011 at 14:08, 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