oop

TwitterFacebook
Get flash to fully experience Pearltrees
http://ejohn.org/blog/javascript-method-overloading/

JavaScript Method Overloading

In a side project that I’ve been working on I built a quick-and-dirty function for doing simple method overloading. For those of you who aren’t familiar with, it’s just a way of mapping a single function call to multiple functions based upon the arguments they accept. Here’s the function in question: // addMethod - By John Resig (MIT Licensed) function addMethod ( object , name , fn ) { var old = object [ name ] ; object [ name ] = function ( ) { if ( fn. length == arguments. length ) return fn. apply ( this , arguments ) ; else if ( typeof old == 'function' ) return old. apply ( this , arguments ) ; } ; } and here is how you might use it: function Users ( ) { addMethod ( this , "find" , function ( ) { // Find all users... } ) ; addMethod ( this , "find" , function ( name ) { // Find a user by name } ) ; addMethod ( this , "find" , function ( first , last ) { // Find a user by first and last name } ) ; }
Using the compact extend function to simulate class-based inheritance in JavaScript we have many of the same features of Ruby classes. One important feature is that classes remain open and that changes in the superclass are automatically also in the subclass. Through the extend function's natural chaining of prototypes we can have this open and inheritable changes. http://peter.michaux.ca/articles/ruby-s-open-classes-and-inheritance-in-javascript

Ruby's Open Classes and Inheritance in JavaScript

darron schall :: Multiple Inheritance in ActionScript 3

http://www.darronschall.com/weblog/archives/000245.cfm Did you know ActionScript 3 supports multiple inheritance? Here's how... Multiple inheritance is actually possible with AS3, despite popular belief that it's not supported. It's not really multiple inheritance in the true sense of the word going by the strict definition... but there's a way to get the job done in AS3 that behaves almost like the real thing.
ActionScript 2.0 OOP by senocular Welcome Here we are going to cover Object Oriented Programming (OOP) in Flash 7 with ActionScript 2.0, a new form of ActionScript introduced in Flash MX 2004. With any luck you've already gone through the sections covering OOP with ActionScript 1.0 . Much of the following will be based off of that foundation, though it is not all necessary to know in order to continue. Here is an outline of all the sections covered.

OOP ActionSript 2.0

http://www.kirupa.com/developer/oop2/AS2OOPindex.htm
http://weblog.openlaszlo.org/archives/2006/02/class-based-oop-in-javascript-done-right/ Max , Adam and I have been working on a scheme to support OpenLaszlo 's LZX language in pure Javascript. As explained in our blog entries, LZX is a blend of class-based and prototype-based object-oriented programming, with an emphasis on class-based programming (because that seems the more widely accepted paradigm). Our current project is to build a new back-end for the LZX compiler to emit "browser Javascript" (i.e., Javascript that will run in all browsers) and to adjust the OpenLaszlo Runtime to also run in browser Javascript. The goal is to make OpenLaszlo run directly in the browser as any good AJAX platform should. My post over the weekend was our latest version, but right after I posted it, I realized there was still a lot of room for improvement. The basic idea was there, but as Max observed, it's really not nice to modify the built-in Javascript classes.

Project Blog » Class-based OOP in Javascript done right