pingo v0.0.2
pingo
pingo is a suite of decorators.
Releases
See the changelog for more information.
Project Site
The project site, see (2) under resources below, provides more insight into the project, including test coverage reports and API documentation.
Contributing
You are very welcome to propose changes and report bugs, or even provide pull requests on github.
See the contributing guidelines for more information.
Contributors
- Carsten Klein Maintainer
- Jay Phelps Contributor
Building
See build process and the available build targets for more information on how to build this.
See also development dependencies and on how to deal with them.
Installation
npm --save pingo
Runtime Dependencies
The dependencies denoted in italics must be provided by the using project.
Documentation
@abstract
The @abstract decorator can be used for decoration of both classes and methods.
Abstract classes cannot be instantiated and invocation of abstract methods will result in an error.
Derived classes must implement all abstract methods or otherwise instantiation of the derived class will result in an error.
import {abstract} from 'pingo';
@abstract
class AbstractAnimal
{
constructor(name)
{
this._name = name;
}
get name()
{
return this._name;
}
@abstract
static family() {}
@abstract
specialMove() {}
}
@abstract
class AbstractSpeakingAnimal extends AbstractAnimal
{
constructor(name, sound)
{
super(name);
this._sound = sound;
}
get sound()
{
return this._sound;
}
speak()
{
return `${this.name}: ${this.sound}`;
}
}
class Cat extends AbstractSpeakingAnimal
{
constructor(name)
{
super(name, 'meooww');
}
static family()
{
return 'Feline';
}
specialMove()
{
return 'sleep';
}
}
class IncompleteImpl extends AbstractAnimal
{}
const cat = new Cat('felicitas');
console.log(cat.speak());
// felicitas: meooww
console.log(cat.specialMove());
// sleep
new AbstractSpeakingAnimal();
// TypeError: abstract class AbstractSpeakingAnimal cannot be instantiated
new IncompleteImpl();
// TypeError: abstract class IncompleteImpl cannot be instantiated
IncompleteImpl.family();
// Error: IncompleteImpl must implement abstract method ...
Similar Projects
Resources
- (1) Github Site
- (2) Project Site