On 5/21/06, Maninder, Singh <[EMAIL PROTECTED]> wrote:

Not all OOP concepts translate very well to JavaScript, but here's how
I treat them.

I could do it any of the following ways -

var Browser = {
  this.getName: function() {
  },
  this.getVersion: function() {
  }
};

This is really creating a namespace called Browser than has the
functions getName and getVersion.

Or I could do -

var Browser = Class.create();
Browser.prototype = {
  initialize: function() {
  },
  getName: function() {
  },
  getVersion: function() {
  }
}

This is creating a class that will later be instantiated.  It can have
state and return results /for the object itself/ (through instance
variables).  All Class.create() is really doing is providing a call to
<object>.initialize() when a new object is instantiated.  You could
theoretically still call Browser.getName() and Browser.getVersion(),
but then you're not taking advantage of initialize() and you shouldn't
bother with Class.create().

Todd
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to