Skip to content
forked from wrongite/oops.js

opps.js is a simple OOP library for Javascript

License

Notifications You must be signed in to change notification settings

MrRemiB/oops.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

oops.js

opps.js is a simple OOP library for Javascript.

Features

  1. Supports methods and attributes inheritance .
  2. Supports getter and setter inheritance.
  3. Supports calling the base class constructor method through "this.__base__".

Example

// Class Animal
// Implement the constructor method of the class Animal
function Animal() {
  console.log("Animal constructor is called");
}

// Assign attributes and methods to Animal
Animal = Animal.Extend(Object, {
    _color: '',
    setColor: function(color) {
        this._color = color;
    },
    getColor: function() {
        return this._color;
    }
});


// Class Bird
function Bird() {
    // Optional: call the base class constructor.
    // Please note that the __base__ is added to this object automatically.
    this.__base__();
    
    console.log("Bird constructor is called");
}

// Extend Animal, add more methods or/and attributes
Bird = Bird.Extend(Animal, {
    fly: function() {
        // ....
    }
});


b = new Bird();
b.setColor('red');  // Calling the inherited method.

console.log(typeof b);
console.log(b instanceof Bird);
console.log(b instanceof Animal);

Output

Animal constructor is called
Bird constructor is called
object
true
true

About

opps.js is a simple OOP library for Javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%