Create items in a class object easily!
Examples
const { Superman } = require('coreplus')('superman');
class Item extends Superman {
constructor(x, y, width, height, id) {
super(x, y, width, height, id);
}
}
console.log(new Item(10, 20, 240, 190, 'block'));
Item { x: 10, y: 20, width: 240, height: 190, id: 'block' }
const { superman } = require('coreplus')('superman');
class Item {
constructor(x, y, width, height, id) {
superman(this, x, y, width, height, id);
}
}
console.log(new Item(10, 20, 240, 190, 'block');
Item { x: 10, y: 20, width: 240, height: 190, id: 'block' }
super(x, y, z) -> this.x = x; this.y = y; this.z = z;
superman(this, x, y, z) -> this.x = x; this.y = y; this.z = z;
Use
Class
First, require the Superman
class using the namespace superman
const { Superman } = require('coreplus')('superman');
Then create a class that extends Superman
class Foo extends Superman {
// ...
}
Then use super
to add the arguments
constructor(foo, bar) {
super(foo, bar);
}
super(
...
);
- Arguments: everything you want to add to the object.
Function
First, require the superman
function using the namespace superman
const { superman } = require('coreplus')('superman');
Then create a class
Then use superman
to add the arguments
constructor(foo, bar) {
superman(this, foo, bar);
}
superman(
Class
, ...);
- Argument: this
keyword.
superman(Class,
...
);
- Arguments: everything you want to add to the object.