Connecting Tech Pros Worldwide Help | Site Map

Classes in Javascript using Prototype library

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 9th, 2006, 07:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Default Classes in Javascript using Prototype library

Hi,

I've been using the prototype.js library[1] to create classes.
Something like

var Sortable = Class.create();
Sortable.prototype = {
initialize: function(element) {
//...
},
// more methods...
}

All of my methods are instance methods. What is the tidiest way to
create class methods and variables?

Thanks,
Peter

[1] - http://prototype.conio.net/


  #2  
Old February 9th, 2006, 08:55 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library

petermichaux@yahoo.com said the following on 2/9/2006 2:58 PM:[color=blue]
> Hi,
>
> I've been using the prototype.js library[1] to create classes.
> Something like
>
> var Sortable = Class.create();
> Sortable.prototype = {
> initialize: function(element) {
> //...
> },
> // more methods...
> }
>
> All of my methods are instance methods. What is the tidiest way to
> create class methods and variables?[/color]

You ask the people at http://prototype.conio.net/ and let them answer
you since it is a technical support question for a piece of software you
want.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
  #3  
Old February 10th, 2006, 04:05 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library

petermichaux@yahoo.com writes:
[color=blue]
> I've been using the prototype.js library[1] to create classes.[/color]
....[color=blue]
> var Sortable = Class.create();[/color]
....[color=blue]
> All of my methods are instance methods. What is the tidiest way to
> create class methods and variables?[/color]

I don't know the prototype library (for help specific to that, I would
guess that they have a web forum somewhere), but what I would do is

Sortable.classMethod = function classMethod(lala) { /* ... */ };

(I'm not particularly fond of the idea of emulating class based
programming in a prototype based language. It's never going to
be exactly what you expect. Ofcourse it's faster than actually
learning prototype based programming, something I won't claim to
have done myself to the level I would prefer :).

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #4  
Old February 10th, 2006, 08:35 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library

Lasse Reichstein Nielsen wrote:[color=blue]
> I'm not particularly fond of the idea of emulating class based
> programming in a prototype based language. It's never going to
> be exactly what you expect. Ofcourse it's faster than actually
> learning prototype based programming, something I won't claim to
> have done myself to the level I would prefer :).[/color]

Ok, that sounds really reasonable. How do I go about learning how to
program a prototype-based language in it's native way? I've read about
prototypes but don't feel at all intuative with them yet. I'm reading
online articles right now but haven't found the one that makes the
fundamental idea click yet.

-Peter

  #5  
Old February 10th, 2006, 08:55 PM
VK
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library


petermichaux@yahoo.com wrote:[color=blue]
> I'm reading
> online articles right now but haven't found the one that makes the
> fundamental idea click yet.[/color]

encapsulation

encapsulation lo

prototype chain

screw the rules

I'm free!

:-)

  #6  
Old February 10th, 2006, 09:05 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library

Thanks VK.

(ummm. Anyone else?)

Peter

VK wrote:[color=blue]
> petermichaux@yahoo.com wrote:[color=green]
> > I'm reading
> > online articles right now but haven't found the one that makes the
> > fundamental idea click yet.[/color]
>
> encapsulation
>
> encapsulation lo
>
> prototype chain
>
> screw the rules
>
> I'm free!
>
> :-)[/color]

  #7  
Old February 10th, 2006, 10:55 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: Classes in Javascript using Prototype library

petermichaux@yahoo.com writes:
[color=blue]
> How do I go about learning how to program a prototype-based language
> in it's native way? I've read about prototypes but don't feel at all
> intuative with them yet. I'm reading online articles right now but
> haven't found the one that makes the fundamental idea click yet.[/color]

You can try this one:
<URL:http://www.zwetan.com/files/Prototype-based_programming.pdf>
I haven't read it yet, only scanned the headlines, but it looks
promising.
Another good guess is Googling for "prototype based programming".

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.