Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

wrongite/oops.js

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
11 Commits
 
 
 
 
 
 

Repository files navigation

oops.js

opps.js is a simple OOP library for Javascript.

Features

  1. Supports methods and attributes inheritance .
  2. Supports getters and setters inheritance. ([Defining getters and setters] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Defining_getters_and_setters))
  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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.