New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

defclass

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defclass

Simple classical inheritance.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

defclass

Simple classical inheritance that is a whopping ten lines. Its Augment without the augment.

In the words of Aadit Shah

No premature optimization. No need to read the documentation of libraries like ClassManager. I can directly focus on the task at hand and optimize those things that really need optimization.

Usage

const defclass = require('defclass');

const Beer = defclass({
  constructor: function (type) {
    this.type = type;
    this.count = 100;
    this.temp = 'cold';
  },
  getADrink: function () {
    --this.count;
    console.log(`Here's a ${this.temp} ${this.type}!`);
  }
});

const favBeer = new Beer('Spotted Cow');
favBeer.getADrink(); // Here's a cold Spotted Cow!

If you need to inherit from another class use extend.

const GrabAnother = defclass.extend(Beer, {
  sing: function () {
    console.log(`${this.count} bottles of ${this.temp} ${this.type}'s on the wall.`);
  }
});

const makeMeDance = new GrabAnother(`John's White Ale`);
makeMeDance.getADrink(); // Here's a John's White Ale!
makeMeDance.sing(); // 99 bottles of cold John's White Ale's on the wall.

Credit

  • Aadit M Shah

Keywords

extend

FAQs

Package last updated on 16 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts