Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript Prototype

 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Pascarello:

Ko Ko Naing,

Using prototype in JavaScript is rather handy. It allows you to create your own methods. I think it is a lot cleaner to code like that. You can develop an oo with JavaScript by using prototypes and classes. Not to advertise, but if you were to pick up Ajax in action, we first develop the code in a straight foward linear approach, then we go back and refactor the code for an oo approach. Makes it so much easier to reuse code on every page. A lot of novices to JavaScript does not know this exists.

You can read about prototype here if you are interested: http://www.webreference.com/js/column34/index.html

A group of use on another forum started to build a large list of prototype functions. I think we are at 70+. My screen name there is A1ien51. http://webdeveloper.com/forum/showthread.php?t=61883

I have a few scripts there to convert times, calc business days, and much more.

If you want to continue talking about prototypes of oo JavaScript, start a new thread.

Eric

So it means that we can do OO JavaScript coding in AJAX. Is it one of the reasons that AJAX was invented for?

You mentioned that re-using existing scripts is very easy when we use prototypes of JavaScript. What is the difference between re-using functions and stuff from tradational JS files and re-using them with prototypes? Since I am more familiar with the traditional way, is there any reason why I have to deal with learning curve on studying prototypes? If there is a big advantage to do that, I will defintely go for that.

Could you please give some ideas for me about this? Thanks a lot...
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ko Ko Naing,

I will make a small write up later on today showing an example how a prototype makes the code seem to flow nicer compared to using regular functions. My boss is screaming right now so I need to try to get a bug fixed!

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic