Skip to content

devdemi/base-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

base-object

Implementation of inheritance in JavaScript

How to build?

  • git clone <repository-url> this repository
  • change into the new directory
  • npm install
  • npm run build

Usage

var Person = BaseObject.extend({
    init: function(name, age) {
        this.name = name;
        this.age = age;
    },
    grow: function() {
        this.age++;
        console.log('Person ' + this.name + ' grows, new age ' + this.age);
    }
})('Ben', 30);

Person.grow();

var Worker = Person.extend({
    init: function(name, age, position) {
        this.init._base.apply(this, arguments);
        this.position = position;
    },
    promote: function() {
        console.log('Worker ' + this.name + ' became Senior ' + this.position);
    },
    grow: function() {
        this.promote();
        this.grow._base.call(this);
    }
})('Vova', 30, 'engineer');

Worker.grow();

About

Implementation of inheritance in JavaScript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published