![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
abstract-class
Advanced tools
Prevents instantiation of a parent class. Optionally defines properties that must be implemented by child classes.
Prevents instantiation of a parent class. Optionally defines properties that must be implemented by child classes. Imitates the functionality provided by abstract classes in languages like Java, PHP, and C++.
Requires Node.js 6.0.0 or above.
npm i abstract-class
The module exports a single function. This function should be called in the constructor of the class you want to declare abstract.
cls
(Function): The abstract parent class.obj
(Object): The this
variable of your object being constructed....props
(any number of: string, number, symbol, or Array thereof): The keys of the properties that a child class should implement.The function does not return a value.
const enforceAbstractClass = require('abstract-class')
class Parent {
constructor () {
enforceAbstractClass(Parent, this, 'title', 'content')
}
}
class Child extends Parent {
get title () { return 'Title' }
}
// Throws Error: Cannot instantiate abstract class `Parent`
const parent = new Parent()
// Throws Error: `Child` must define the abstract property `content`
const child = new Child()
Constructing a Parent
object fails because the class is marked abstract. Constructing a Child
object also fails because Child
does not define content
.
You can also use the bind operator pattern:
const Abstract = require('abstract-class')
class Parent {
constructor () {
Parent::Abstract(this)
}
}
// Throws Error: Cannot instantiate abstract class `Parent`
const parent = new Parent()
If the child class provides its own constructor and fails to call the parent constructor, property abstraction will not be enforced.
FAQs
Prevents instantiation of a parent class. Optionally defines properties that must be implemented by child classes.
We found that abstract-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.