Simple-JavaScript-OOP-Library

Small but tricky piece of code in JavaScript which allows you to define classes with properties and methods, supports inheritance and instanceof operator.

Usage

var Parent = new Class({
  init: function (...) { // constructor
    ...
  },

  property_1: ..., // also will be property of child

  property_2: ...,

  method_1: function (...) { // also will be method of child
     ...
  },

  method_2: function (...) {
    ...
  }
});

var Child = new Class({
  parent: Parent, // inheritance

  init: function (...) { // constructor
    ...
  },

  property_2: ..., // overrides parent's property

  property_3: ...,

  method_2: function (...) { // overrides parent's method
    ...
  },

  method_3: function (...) {
    ...
  }
});

if (child instanceof Parent) { // works
  ...
}

Author (Speransky Danil): Personal Page | LinkedIn | GitHub | StackOverflow