Functional Classes in JavaScript (ES5)

This is tricky subject as JavaScript didn’t have classes in the language before 2015. So when classes was talked about before ES6 it was different ways to achieve the same functionality Classes have in other languages though it wasn’t strictly classes. Functional classes is one of those ways. It could be boiled down to that a Class is just a function that creates a lot of similar objects in JavaScript, this isn’t not strictly true when it comes to other programming languages or the latest version of JavaScript ES6 but it’s best to think of it that way when speaking about Classes in ES5.
Here is an example of how the Person class would look like with functional classes the ES5 way:

function extend(destination, source) {
  for (var k in source) {
    if (source.hasOwnProperty(k)) {
      destination[k] = source[k];
  return destination; 

var Person = function(age) {
  var obj = {age: age};
  extend(obj, Person.methods);
  return obj;

Person.methods = {  
  ageing : function(){

var ben = new Person(26);
console.log(ben.age); // -> 27

Add your comment