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

bindall-standalone

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bindall-standalone - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.npmignore

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,

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