Monday, July 1, 2013

Classes and Attributes

I published the last update on the tokenizer yesterday evening, I am now moving to another interesting topic meaning the way JavaScript handles Object Oriented Programming: this is called prototyping.
Please search for JavaScript prototyping, you will find really good explanations of the concept, for instance:
To make a long story short, classes do not exist in JavaScript. However, it is possible to create instances of objects where the members are defined through this prototyping. The most interesting fact is that inheritance is possible. However, real OOP concepts such as member visibility (private, protected, public), abstracts or method overriding are not built-in. There are ways to reach the same level of functionality but with development costs.


I will not pretend I invented the code you will see because the main part of it has been extracted from J.Reisig's excellent blog: http://ejohn.org/blog/simple-javascript-inheritance.

However, I tried to improve the idea by adding attributes, a concept that I discovered while coding C# (for instance, please check this intersting thread: http://stackoverflow.com/questions/144833/most-useful-attributes). Indeed, it allows to qualify the class members in order to alter the way they are handled.

This step is an important one for the library as it will structure its development.

Stay tuned!