Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
define-accessor
Advanced tools
Define Accessor is a simple utility for defining a getter/setter in ES5 with the same property descriptor as an ES2015 class accessor.
Install with npm:
npm install --save define-accessor
In ES2015, we might do this:
class Octopus {
constructor(name) {
this.name = name;
}
get nameEqualsTentacles() {
return this.name.length === 8;
}
}
In ES5, we can do this:
var defineAccessor = require('define-accessor');
function Octopus(name) {
this.name = name;
}
defineAccessor(Octopus, 'nameEqualsTentacles', function() {
return this.name.length === 8;
});
And here is Vladimir:
new Octopus('Vladimir').nameEqualsTentacles; // -> true
defineAccessor(constructor, prop, [getter], [setter])
Param | Type | Description |
---|---|---|
constructor | function | The constructor function whose prototype the accessor will be added to |
prop | string | The property name of the accessor |
[getter] | function | A getter function (optional) |
[setter] | function | A setter function (optional) |
Copyright © 2016 Akim McMath. Licensed under the MIT License.
FAQs
Define an ES2015 class getter/setter in ES5
The npm package define-accessor receives a total of 2 weekly downloads. As such, define-accessor popularity was classified as not popular.
We found that define-accessor 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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.