Classes in Javascript using Prototype library

P

petermichaux

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/
 
R

Randy Webb

(e-mail address removed) said the following on 2/9/2006 2:58 PM:
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?

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

Lasse Reichstein Nielsen

I've been using the prototype.js library[1] to create classes. ....
var Sortable = Class.create(); ....
All of my methods are instance methods. What is the tidiest way to
create class methods and variables?

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
 
P

petermichaux

Lasse said:
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 :).

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
 
V

VK

I'm reading
online articles right now but haven't found the one that makes the
fundamental idea click yet.

encapsulation

encapsulation lo

prototype chain

screw the rules

I'm free!

:)
 
L

Lasse Reichstein Nielsen

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top