Your second example simply implies doSomething is a static method of the ObjectName class (i.e. instantiation is not necessary) and is a perfect testament to how proto accurately and easily allows for traditional OO programming styles... in that case just be aware that the function is executing in a static context and "this" will refer to the function itself (unless you .bind() the call to another object).

On 7/20/06, Bauser, Joseph (Joe) <[EMAIL PROTECTED]> wrote:
I believe the only difference between the two is that in the first you're creating a prototyped class, where in the second you're creating a static namespace containing functions.

The only extra overhead you'll see is from the call to Class.create().

Cheers,
Joe

-----Original Message-----
From: [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED]]On Behalf Of Brian Feliciano
Sent: Thursday, July 20, 2006 12:28 PM
To: rails-spinoffs@lists.rubyonrails.org
Subject: Re: [Rails-spinoffs] _javascript_ Namespacing Question


wow! this list is hot! :D
thanks for the instant replies! i'm starting to love this list. :D

my last question ( of this thread :D )
is there a difference between:

var ObjectName = Class.create();
ObjectName.prototype = {
  initialize: function () {},
  doThis: function () {}
}
var obj = new ObjectName();
obj.doThis();

and

var ObjectName = {
  initialize: function () {},
  doThis: function () {}
}
ObjectName.doThis();

i know their difference coding-wise, but im a bit concerned about speed and performance and efficiency. (as you may have already noticed, im a bit paranoid about performance/speed)




On 7/21/06, Ryan Gahl <[EMAIL PROTECTED]> wrote:
Nope, that should work out just fine, but I would just call that "namespacing" (YUI didn't invent that concept)... :-)
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

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

Reply via email to