Hi,

>       I'm trying to understand the use of OOP with jQuery. In creating
> a fairly complex web application I have made extensive use of the class
> attribute. Further, I've been successful in binding events to the classes,
> setting styles, and that sort of thing.
>       What I have not had much luck with is the creation of class attributes
> or methods. I simply don't understand the technique, and this seems to be
> the one spot where the (really great!) docs are a bit sparse.

As much as I understand, you try to use the HTML class attribute as class for 
programming. The first thing is, that javaScript doesn't have classes, the 
second thing is that the two concepts of "class" don't have much to do with 
each other.

In javaScript you do object-oriented Programming with prototypes:

function Patient(age) {
        // this is something like the constructor
        this.age = age
}
Patient.prototype = {
        // here we define a prototype for all myClass objects.
        myValue: 11
};
function femalePatient(shoesize) {
        Patient.apply(this,42);
        this.shoesize = shoesize
}
femalePatient.prototype = new Patient(0); // here we derive
femalePatient.prototype.shoesize = 38;

var myObject = new myDerivedClass(37);
alert(myObject.age); // alerts 42
alert(myObject.shoesize); // alerts 37

A Prototype is an Object that is copied for each instance.

>       The docs suggest extend() ...

extend() just extends an object. You can add attributes and functions 
dynamically to existing objects with javaScript. extend() simply takes all 
attributes and functions of the provided object and adds them to the other 
object. You can use it to exentend a prototype as well of course.

Christof

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to