PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Eight Weeks of Prototype: Week 6, Writing JavaScript Classes with Prototype

This article is part of the series “Eight Weeks of Prototype”. Eight Weeks of Prototype is a series of articles covering the most important aspects of JavaScript development with the Prototype framework. Prototype is a JavaScript framework used to help developers easily create powerful web applications that work across all modern web browsers.. Read more about Eight Weeks of Prototype...

Introduction

While JavaScript is by design an object-oriented language, it hasn't always been the easiest language to create nicely structured code that is easily maintainable. Prototype helps with this by providing a number of useful features for creating classes, such as the ability to extend classes and to easily group all functions together by using function binding. In this article I will show you how to create classes using JavaScript and Prototype.

To begin with, I'll show you how to define classes and how to create the class constructor. Next I will show you how to create child classes by extending your classes. After this I will introduce you to function binding and how it applies to the development of JavaScript classes.

Next I will show to create a string representation of instances of your created classes, then how to create custom enumerables (as mentioned in the third article in this series).

This article assumes you have read and understood the first five articles in this series, and also that you have at least a basic knowledge of how object-oriented programming (OOP) works.

In This Article