autobind-decorator
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -1,6 +0,1 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
/** | ||
@@ -20,2 +15,7 @@ * @copyright 2015, Andrey Popp <8mayday@gmail.com> | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports['default'] = autobind; | ||
@@ -40,15 +40,4 @@ | ||
// (Using reflect to get all keys including symbols) | ||
var keys = undefined; | ||
// Use Reflect if exists | ||
if (typeof Reflect !== 'undefined') { | ||
keys = Reflect.ownKeys(target.prototype); | ||
} else { | ||
keys = Object.getOwnPropertyNames(target.prototype); | ||
// use symbols if support is provided | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
keys = keys.concat(Object.getOwnPropertySymbols(target.prototype)); | ||
} | ||
} | ||
keys.forEach(function (key) { | ||
console.log(Object.getOwnPropertyNames(), Object.getOwnProperySymbols()); | ||
Reflect.ownKeys(target.prototype).forEach(function (key) { | ||
// Ignore special case target method | ||
@@ -55,0 +44,0 @@ if (key === 'constructor') { |
{ | ||
"name": "autobind-decorator", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Decorator for binding method to an object", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"author": "Andrey Popp <8mayday@gmail.com>", | ||
@@ -7,0 +10,0 @@ "license": "MIT", |
# autobind decorator | ||
This is a class or method decorator which will bind methods it to an | ||
object so `this` always points to an object instance within a method. | ||
A class or method decorator which binds methods to the instance | ||
so `this` is always correct, even when the method is detached. | ||
This is particularly useful for situations like React components, where | ||
you often pass methods as event handlers and would otherwise need to | ||
`.bind(this)`. | ||
``` | ||
Before: | ||
<button onClick={ this.handleClick.bind(this) }></button> | ||
After: | ||
<button onClick={ this.handleClick }></button> | ||
``` | ||
As decorators are a part of future ES7 standard they can only be used with | ||
@@ -11,7 +22,6 @@ transpilers such as [Babel](http://babeljs.io). | ||
% npm install autobind-decorator core-js | ||
% npm install autobind-decorator | ||
Example: | ||
import 'core-js/modules/es6.reflect' // Reflect polyfill is required | ||
import autobind from 'autobind-decorator' | ||
@@ -18,0 +28,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49
16850
72
1