1.0.0 • Published 4 years ago

superman.js v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Superman

🧭 Simple low cost package that makes long object classes easier to make!

Download

With node package manager npm, run:

$ npm install superman.js

Use

On the top of your JavaScript file, require superman (class or function):

// Class:
const { Superman } = require("superman.js");

// Function:
const { superman } = require("superman.js");

Class

When you want to use the class, extend the class that you are going to use the shortcut with like this:

class Item extends Superman {
  // ...
}

Then, in the constructor you can call the super to run the shortcut:

class Item extends Superman {
  constructor(id, x, y, width, height) {
    super(Item, id, x, y, width, height);
  }
}

Arguments:

  • super( Item , id, x, y, width, height); - This argument is the class name in which the constructor function is in.
  • super(Item, id , x, y, width, height ); - These last arguments are the arguments you want to add to the class object.

Function

The function is like the Class but you don't have to use extend, you can run it in the constructor function like this:

class Item {
  constructor(id, x, y, width, height) {
    superman(this, Item, id, x, y, width, height);
  }
}

Arguments:

  • superman( this , Item, id, x, y, width, height); - This argument is just the this keyword.
  • superman(this, Item , id, x, y, width, height); - This argument is the class name in which the constructor function is in.
  • superman(this, Item, id, x, y, width, height ); - These last arguments are the arguments you want to add to the class object.

Why?

I created this package because of this simple pet peeve:

class Item {
  constructor(id, x, y, width, height, name, _class, construction, type) {
    this.id = id;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
    this.name = name;
    this._class = _class;
    (this.construction = construction), (this.type = type);
  }
}
1.0.0

4 years ago