LB.
LB.

Reputation: 14112

Sub-classing in jQuery

How would one go about in subclassing a class in jQuery?

Specifically, I want to be able to subclass this class:

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm

and override its methods.

Some syntax helpers would help. Thanks!

Upvotes: 2

Views: 85

Answers (2)

justkt
justkt

Reputation: 14766

Javascript uses prototypal inheritance. Crockford has an excellent article on how that's different from classical inheritance. Prototypal inheritance in JavaScript allows you to do all sorts of things that C++, Java, C#, etc. may not allow you to do and in ways that you may not expect. Because that's what's built into Javascript, others have created methods of extension such as closure-based inheritance where classes are created with closures instead of the standard formula.

The library that you linked to states in its documentation that is based on dojo, not jQuery. The two are both Javascript frameworks and are different.

For inheritance in dojo I doubt you could do much better than the references in this answer to a similar question about inheritance in dojo. One option suggests looking at dojo.delegate(); and dojo.declare();. This article has a good overview of classes using dojo in Javascript.

Upvotes: 2

wsanville
wsanville

Reputation: 37516

Check out Douglas Crockford's article, Classical Inheritance in JavaScript. It's really well written and includes different examples of inheritance in Javascript.

Upvotes: 1

Related Questions