Connecting Tech Pros Worldwide Help | Site Map

Classes in Javascript using Prototype library

  #1  
Old February 9th, 2006, 08:15 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a
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, 09:55 PM
Randy Webb
Guest
 
Posts: n/a

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, 05:05 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

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, 09:35 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a

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, 09:55 PM
VK
Guest
 
Posts: n/a

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, 10:05 PM
petermichaux@yahoo.com
Guest
 
Posts: n/a

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, 11:55 PM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
to learn jQuery if already using prototype liketofindoutwhy answers 83 June 27th, 2008 08:10 PM
JavaScript GUI library idea petermichaux@gmail.com answers 21 March 27th, 2006 05:15 PM
Errors in NS 4.7, works in recent browsers, please help ASallade answers 2 July 20th, 2005 02:46 PM
OO JavaScript? Who's using it? Alex Fitzpatrick answers 6 July 20th, 2005 02:06 PM