Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
add-accessors
Advanced tools
This is a javascript library for adding getters, setters, and a "destroy" method that unsets member variables to a class.
Works with Node.js and CommonJS bundlers like Browserify.
npm install --save add-accessors
Examples use ES6, but ES6 is not necessary to use addAccessors. (Babel is an excellent tool to use to get ES6!)
const addAccessors = require('add-accessors');
class Foo {
constructor(x) {
this._x = x;
this._destroyable = {
destroy() {
console.log('destroyable destroy called');
}
};
this._bar = {
remove() {
console.log('bar remove called');
}
};
}
}
addAccessors(Foo.prototype, [
{name: '_x', get: true, set: true},
{name: '_destroyable', destroy: true},
{name: '_bar', destroy: true, destroyMethod: 'remove'}
]);
const foo = new Foo(42);
console.log(foo.getX()); // 42
foo.setX(123);
console.log(foo.getX()); // 123
foo.destroy();
// "destroyable destroy called"
// "bar remove called"
console.log(foo.getX()); // undefined
The addAccessors
function takes an object (such as a class prototype) and an
array describing the member variables. Each member variable descriptor is made
up of the following properties:
Getters and setter methods are added for the specified member variables, and a
"destroy" method is added to the object which sets all of the member variables
to undefined
, and calls destroy methods on the values of the member variables
that were set to have it called.
If the object already had a "destroy" method before addAccessors was called on it, then the new "destroy" method will call it at the end, so addAccessors will work correctly with inheritance.
Additional checks are done at run-time to make sure that addAccessors is used correctly. These checks can be disabled by setting the NODE_ENV environment variable to "production".
FAQs
Utility for adding getters and setters to classes
The npm package add-accessors receives a total of 5 weekly downloads. As such, add-accessors popularity was classified as not popular.
We found that add-accessors 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.