This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript Prototype Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript Prototype" Watch "JavaScript Prototype" New topic

JavaScript Prototype

Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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:

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.

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.


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...

Co-author of SCMAD Exam Guide, Author of JMADPlus
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
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!

I agree. Here's the link:
subject: JavaScript Prototype
It's not a secret anymore!