Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

define-static-method

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

define-static-method

Define an ES2015 class static method in ES5

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Define Static Method

Version License Build Coverage Dependencies

Define Static Method is a simple utility for defining a static method in ES5 with the same property descriptor as an ES2015 class method.

Install

Install with npm:

npm install --save define-static-method

Usage

In ES2015, we might do this:

class Squid {
  constructor(name) {
    this.name = name;
  }
  static createVladimir() {
    return new Squid('Vladimir');
  }
}

In ES5, we can do this:

var defineStatic = require('define-static-method');

function Squid(name) {
  this.name = name;
}

defineStatic(Squid, 'createVladimir', function() {
  return new Squid('Vladimir');
});

And here is Vladimir:

Squid.createVladimir().name; // -> 'Vladimir'

API

defineStaticMethod(constructor, prop, method)
ParamTypeDescription
constructorfunctionThe constructor function the method will be added to
propstringThe property name of the method
methodfunctionThe static method to add

License

Copyright © 2016 Akim McMath. Licensed under the MIT License.

Keywords

FAQs

Package last updated on 21 Jun 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc