Jul 2, 2007

Static Method or Singleton

You don't need a "new" operation to create object to use the method.

            // A static method attached to the User object
            User.cloneUser = function( user ) {
            // Create, and return, a new user
            return new User(
            // that is a clone of the other user object
            user.getName(),
            user.getAge()
            );
            };
            

Another way to to do is like the following

            User = {
            run:function(){ alert("run"); }
            }

            User.walk = function(){alert("walk");}

            User.run();
            User.walk();