Like this page? Share it with others!    Lists AddThis! sites that you can use to share the content of this site with someone.

Webmaster's Corner

Thursday, March 27, 2008

JavaScript..."prototype" or Just Add a Property or Method?

Do I prototype my objects with my properties and methods or do I just add properties in the constructor?

Think of it this way. The "prototype" methods and properties are always a part of your objects. Create a property or method without the prototype keyword if you want to decorate an existing object. Why? Because the more you prototype, the heavier the object becomes, so... prototype carefully. I guess an exception to this is if you are creating a singleton class, prototyping is probably not necessary as it is not instantiated so just going this.SomeMethod = ... is fine. Anybody have comments on that?

The Prototype JS framework is great but all the "prototyping" creates heavier objects that inherently might not have been as heavy. As well by prototyping an inherent data type like Object, you risk breaking existing JavaScript code that tries to integrate with a framework like Prototype because it's "prototype"ed all these new properties and methods on HTMLElements or the Object inherent data types.

Having said all that, JavaScript frameworks are great for RAD deployment, but I still stick by my guns when I say that with lots of data and objects on a page, this heavily protoyped framework mindset definitely slows things down. See my original post.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home

About | Add My Club or Tourney | Questions, Comments | Report Site Problems | Site Map | Admin Panel
Site developed by webnick

subscribe to one of our blog feeds
XML Rugby FeedsRSS Rugby Feeds

Copyright © 2009 rugbyincanada.com (not affiliated with Rugby Canada)