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-method
Advanced tools
Define Method is a simple utility for defining an instance method in ES5 with the same property descriptor as an ES2015 class method.
Install with npm:
npm install --save define-method
In ES2015, we might do this:
class Fish {
constructor(name) {
this.name = name;
}
greet() {
console.log(`Hello, my name is ${this.name} the fish.`);
}
}
In ES5, we can do this:
var defineMethod = require('define-method');
function Fish(name) {
this.name = name;
}
defineMethod(Fish, 'greet', function() {
console.log('Hello, my name is ' + this.name + ' the fish.');
});
And here is Vladimir:
new Fish('Vladimir').greet(); // 'Hello, my name is Vladimir the fish.'
defineMethod(constructor, prop, method)
Param | Type | Description |
---|---|---|
constructor | function | The constructor function whose prototype the method will be added to |
prop | string | The property name of the method |
method | function | The method to add |
Copyright © 2016 Akim McMath. Licensed under the MIT License.
FAQs
Define an ES2015 class method in ES5
The npm package define-method receives a total of 1 weekly downloads. As such, define-method popularity was classified as not popular.
We found that define-method 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.