bindall-standalone
Advanced tools
Comparing version 1.0.1 to 1.0.2
26
index.js
'use strict'; | ||
module.exports = function(obj) { | ||
var funcs = Array.prototype.slice.call(arguments, 1); | ||
if (funcs.length === 0) throw new Error('bindAll must be passed function names'); | ||
funcs.forEach(function(f) { | ||
obj[f] = obj[f].bind(obj); | ||
}); | ||
return obj; | ||
module.exports = function(object) { | ||
var functions = Array.prototype.slice.call(arguments, 1); | ||
if (functions.length === 0) { | ||
var toString = Object.prototype.toString; | ||
for (var method in object) { | ||
if(object.hasOwnProperty(method)) { | ||
if(typeof object[method] == 'function' && toString.call(object[method]) == "[object Function]") { | ||
functions.push(method); | ||
} | ||
} | ||
} | ||
} | ||
for(var i = 0; i < functions.length; i++) { | ||
var f = functions[i]; | ||
object[f] = object[f].bind(object); | ||
} | ||
}; |
{ | ||
"name": "bindall-standalone", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Standalone version of underscore's `_.bindAll()` function for IE9+ browsers.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/bindall.js | tap-spec" | ||
}, | ||
@@ -21,3 +21,7 @@ "repository": { | ||
"url": "https://github.com/ayamflow/bindall-standalone/issues" | ||
}, | ||
"devDependencies": { | ||
"tape": "~2.12.3", | ||
"tap-spec": "~0.1.9" | ||
} | ||
} |
@@ -7,14 +7,28 @@ bindall-standalone | ||
Taken from the [underscore source](http://underscorejs.org/docs/underscore.html) and adapted to work without underscore. | ||
Works with require() e.g. for node.js, browserify or component(1). | ||
Works with require() e.g. node.js, browserify or component(1). | ||
## API | ||
Useful for avoiding the addEventListener/on memory leak when binding a function. | ||
``` | ||
bindAll(object, 'func1', 'func2', ...) | ||
mediator.on('foo', this.bar.bind(this)); | ||
mediator.off('foo', this.bar.bind(this)); | ||
// will never be unbinded because this.bar.bind(this) != this.bar.bind(this) | ||
``` | ||
Mutates all functions from `object`, passed as strings (such as `func1` and `func2`) so they always will be called with the countext bound to the `object`. | ||
## Installation | ||
`npm install bindall-standalone --save` | ||
## API | ||
### `bindAll(object, *methods);` | ||
Mutates all methods from `object`, passed as a list of strings (such as `'foo', 'bar'`) so they always will be called with the context bound to the `object`. | ||
### `bindAll(object);` | ||
Bind **ALL** methods available on the object. | ||
## Usage | ||
``` | ||
var bindAll = require('bindall-standalone'); | ||
var object = { | ||
@@ -21,0 +35,0 @@ foo: 10, |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5691
6
79
1
48
0
2