JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 289355
  • Score
    100M100P100Q184288F
  • License MIT

Decorator for binding method to an object

Package Exports

  • autobind-decorator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (autobind-decorator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

autobind decorator

This is a method decorator which is when applied to a method binds it to an object so this always points to an object instance within a method.

As decorators are a part of future ES7 standard they can only be used with transpilers such as Babel.

Installation:

% npm install autobind-decorator

Example:

import autobind from 'autobind-decorator'

class Component {

  constructor(value) {
    this.value = value
  }

  @autobind
  method() {
    return this.value
  }
}

let component = new Component(42)
let method = component.method // .bind(component) isn't needed!
method() // returns 42