Good example OO JS?

Can someone point me in the right direction of some real object oriented javascript? I learn OO for javascript from several books, but all of the examples in these books come down to a canine object inherited from an animal prototype or the like. I really want to see something more substantial.

I looked at jQuery and similar libraries (base, prototype), but I consider them examples. I was looking for a script where I see visible inheritance (classic or protoypal).

+5
source share
2 answers

Good examples of the โ€œreal worldโ€ for learning OO javascript is to really learn some of the javascript frameworks. Some of them support and use OO in their own framework code:

They provide an excellent link and various strategies for writing JavaScript JavaScript.

+5
source

IMO, the prototype javascript thingie is very useful, and classic OOP is not needed.

As an example in the real world, consider the google maps v3 api . Let the new OverlayView be implemented:


// implement an OverlayView //
MyOverlay.prototype = new google.maps.OverlayView();

// the "constructor" function // function MyOverlay (position, node, map) {// set the parameters // this.position = position; this.node = node; this.map = map; this.setMap (this.map); }

// required onAdd function // MyOverlay.prototype.onAdd = function() { // observe the getPanes function inherited from OverlayView // var panes = this.getPanes(); // bla bla // }

// required draw function // MyOverlay.prototype.draw = function() { // bla bla // } // .. other functions //

// now instantiate an object // var instance = new MyOverlay(position, node, map);

, (, Prototype, dojo, jquery ..) .

+2

All Articles