OOP in JavaScript - Part 3: Extending classes
After I've already covered normal and static classes, Part 3 is about extending classes. As before, basic knowledge in OOP and JavaScript is needed.First, let's create a class Human with setters and getters for the age:function Human(){ }Human.prototype._age = 0;Human.prototype.setAge = function(age){ if (typeof age != 'number') { throw('Invalid Age provided'); } this._age = age;};
OOP in JavaScript - Part 2: Static classes and Singleton
After I've covered normal classes in Part 1 of the series, the second part will focus on static classes and singletons. As before basic OOP and JavaScript knowledge is needed.Generally writing and using static classes is monstly the same as normal classes. The difference is that you don't need to instantiate the object with new and you can't use prototyping nor this, since everything is in static context. One useful implementation for static classes is the Registry Design Pattern. First off we create the
OOP in JavaScript - Part 1: Writing classes
OOP in JavaScript works a bit different than known from other languages. That's why I decided to do a series of "OOP in JavaScript" blogposts, where I want to show how OOP in JavaScript works. The series will discuss topics like creating classes, prototyping, extending classes, static classes, scoping, and so on. To understand these postings a basic knowledge of JavaScript and OOP is needed. This first part is about creating classes/prototyping.First thing you need to know: There is now keyword class in JavaScript. In order to create a class in JavaScript, all you have to do is to create a function and then create a new class instance by using the known keyword
Not enough data.
Calculated for blogs with 20+ followers.
Questions? contact: networkedblogs@ninua.com
Copyright (C) 2008, Ninua, Inc.