class-autobind
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -28,4 +28,6 @@ 'use strict'; | ||
function autobind(instance) { | ||
var proto = instance.constructor.prototype; | ||
function autobind(instance, proto) { | ||
if (proto == null) { | ||
proto = Object.getPrototypeOf(instance); | ||
} | ||
var propertyNames = Object.getOwnPropertyNames(proto); | ||
@@ -32,0 +34,0 @@ for (var _iterator = propertyNames, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { |
{ | ||
"name": "class-autobind", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Method auto-bind for ES6 (ES2015) classes", | ||
@@ -16,3 +16,3 @@ "main": "lib/autobind.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.9.0", | ||
"babel-cli": "^6.10.1", | ||
"babel-core": "^6.9.1", | ||
@@ -25,3 +25,3 @@ "babel-eslint": "^6.0.4", | ||
"babel-preset-stage-2": "^6.5.0", | ||
"eslint": "^2.11.1", | ||
"eslint": "^2.12.0", | ||
"eslint-plugin-babel": "^3.2.0", | ||
@@ -31,3 +31,3 @@ "eslint-plugin-flow-vars": "^0.4.0", | ||
"expect": "^1.20.1", | ||
"flow-bin": "^0.26.0", | ||
"flow-bin": "^0.27.0", | ||
"mocha": "^2.5.3", | ||
@@ -34,0 +34,0 @@ "rimraf": "^2.5.2" |
@@ -28,4 +28,26 @@ # Method auto-bind for ES6 (ES2015) classes | ||
## Advanced Usage: | ||
If your component will possibly be subclassed (you really should not do this, but some third-party libraries like [react-css-modules](https://npmjs.com/package/react-css-modules) do so) then you will need to specify which prototype will be the source of methods that are to be automatically bound. | ||
```js | ||
import autobind from 'class-autobind'; | ||
class MyComponent extends React.Component { | ||
constructor() { | ||
super(...arguments); | ||
autobind(this, MyComponent.prototype); // Note the second parameter. | ||
} | ||
render() { | ||
/* ... */ | ||
} | ||
} | ||
class MySubClassedComponent extends MyComponent { | ||
/* This is probably a very bad idea. */ | ||
} | ||
``` | ||
## License | ||
This software is [BSD Licensed](/LICENSE). |
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
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
5003
42
53