Peter Michaux
2006-Jul-24 16:24 UTC
Suggested class-based inheritance scheme for Prototype.js
Hi, Prototype.js is going through some troubled times with class-based inheritance. A few days ago I mentioned my suggested solution of using Kevin Lindsay''s eight line extend function to solve these problems. http://kevlindev.com/tutorials/javascript/inheritance/index.htm I''ve blogged about how this tiny extend function gives us so much important Ruby-like behavior. Below are three examples showing both Ruby and JavaScript versions of each. http://peter.michaux.ca/articles/2006/06/02/class-based-inheritance-in-javascript http://peter.michaux.ca/articles/2006/07/24/ruby-open-classes-and-inheritance-in-javascript http://peter.michaux.ca/articles/2006/07/24/ruby-module-remove-method-in-javascript You will see that this approach to class-based inheritance in JavaScript is very clean and powerful and dramatically reduces the amount of code needed to set up classes and inheritance compared with Prototype.js 1.5''s approach. This approach also enables the open-class concept as shown in the second and third examples which is not possible with the current Object.extend function. Peter