Connecting Tech Pros Worldwide Forums | Help | Site Map

Classes in Javascript using Prototype library

petermichaux@yahoo.com
Guest
 
Posts: n/a
#1: Feb 9 '06
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/


Randy Webb
Guest
 
Posts: n/a
#2: Feb 9 '06

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/
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Feb 10 '06

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.'
petermichaux@yahoo.com
Guest
 
Posts: n/a
#4: Feb 10 '06

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

VK
Guest
 
Posts: n/a
#5: Feb 10 '06

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!

:-)

petermichaux@yahoo.com
Guest
 
Posts: n/a
#6: Feb 10 '06

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]

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#7: Feb 10 '06

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.'
Closed Thread