aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes is prototype required? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "is prototype required?" Watch "is prototype required?" New topic
Author

is prototype required?

jim cato
Greenhorn

Joined: Jul 15, 2008
Posts: 21
Hi Stoyan,

I've used Javascript mainly in it's OOP form since I believe OOP is the only way to go. But I have not found a need for prototypes. The reason for this is perhaps due to the small size of any script I have written.

But do you think creating inheritance hierarchies in javascript is useful bearing in mind the move away from client side scripting?

Or do you think the emergence of asynchronous technologies such as AJAX will reinvigorate the demand for client side scripting and thus require more robust code, which is perhaps available through OO hierarchies and prototypes?

Cheers,
James
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Originally posted by jim cato:
Or do you think the emergence of asynchronous technologies such as AJAX will reinvigorate the demand for client side scripting ...

This has been going on for years now -- ever since the emergence of Ajax. I'm not sure what "move away from client scripting" you've seen, but I've seen the exact opposite. The advent of Ajax has brought JavaScript and client-side scripting into the limelight like never before.

Just look at the emergence of client-side toolkits, and the vast number of books being written on the subject, as evidence.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jim cato
Greenhorn

Joined: Jul 15, 2008
Posts: 21
I think where I'm coming from is the server side, where client scripting is painful mainly because of browser incompatibilities, limited development tools and a lack of control over the client itself.

While it is essential in some circumstances I try to avoid large complex models.

But yes, I'm sure you're right: I stand corrected.

So let me rephrase the question.

Do you think that since demand for client side scripting is greater than ever there is a need to address its problems; hence a detailed look at the OOP model and how it can be applied to javascript?
Stoyan Stefanov
author
Ranch Hand

Joined: Jul 16, 2008
Posts: 61
As Bear Bibeault said, the client technologies are back, we're seeing movement to "fat client" approaches where a lot of processing is happening in the browser, resulting in fewer and smaller server roundtrips and hence, more responsive applications. The plethora of framworks and libraries are one proof, job listings are another, important one if you ask me I know my employer (Yahoo!) is constantly looking for talented front-end people. So yeah, btw, anyone interested in a FE position, feel free to PM me.

For the prototypes, yes, they are definitely useful for inheritance, but not only. There are many ways to do inheritance in JavaScript, most include the prototype and the basic example is:



Every function in javascript is actually an object with properties, and one of the properties that each function has is the prototype.

Interesting thing is that all objects created with a specific constructor will "see" the stuff you add to the prototype live, even after they are created. This allows you to extend the language's built in constructors.

For example you can add a new method to all arrays.



You can also easily add functionality to any object ever created in your program:



This gives you a lot of power, so naturally it's a little dangerous. Some people like this so much, they even named whole libraries after it

At the end, every object has a link to its prototype, that is the prototype property of the constructor function used to create the object. In Firefox and other browsers (not IE), you actually have access to the link as a normal property called __proto__. So for example:



<a href="http://www.thinkinginjavascript.com" target="_blank" rel="nofollow">my OOJS book</a>
Stoyan Stefanov
author
Ranch Hand

Joined: Jul 16, 2008
Posts: 61
oh, one other thing, in javascript practice, it's rare that you'll see deep inheritance chains. It's a dynamic language, objects can be changed at any time and often there are elegant solutions without meny levels of inheritance.
jim cato
Greenhorn

Joined: Jul 15, 2008
Posts: 21
Thanks for your input: very interesting.
Good luck with the book.

Jim
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61756
    
  67

Originally posted by Stoyan Stefanov:
oh, one other thing, in javascript practice, it's rare that you'll see deep inheritance chains. It's a dynamic language, objects can be changed at any time and often there are elegant solutions without meny levels of inheritance.


Quoted for emphasis.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is prototype required?