{"id":22356855,"url":"https://github.com/ayamflow/bindall-standalone","last_synced_at":"2025-07-30T10:32:40.966Z","repository":{"id":16879422,"uuid":"19639918","full_name":"ayamflow/bindall-standalone","owner":"ayamflow","description":"Standalone version of underscore's _.bindAll() function","archived":false,"fork":false,"pushed_at":"2014-10-23T15:20:29.000Z","size":388,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-09T11:13:13.810Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ayamflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-10T11:32:54.000Z","updated_at":"2017-08-12T14:11:14.000Z","dependencies_parsed_at":"2022-08-27T00:02:03.998Z","dependency_job_id":null,"html_url":"https://github.com/ayamflow/bindall-standalone","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Fbindall-standalone","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Fbindall-standalone/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Fbindall-standalone/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ayamflow%2Fbindall-standalone/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ayamflow","download_url":"https://codeload.github.com/ayamflow/bindall-standalone/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228124602,"owners_count":17873170,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T14:12:13.079Z","updated_at":"2024-12-04T14:12:13.732Z","avatar_url":"https://github.com/ayamflow.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"bindall-standalone\n==================\n\nAllow to permanently mutate an object's method so it context `this` will always be bound to this object.\n\nAllow to avoid the non-unbindable listeners registered via `emitter.on(foo, this.bar.bind(this));`.\n\n## Installation\n`npm install bindall-standalone --save`\n\nThen just `var bindAll = require('bindall-standalone')`. Works with require() e.g. node.js, browserify or component(1).\n\n## API\n### `bindAll(object, *methods);`\n\nMutates 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`.\n\n### `bindAll(object);`\nBind **ALL** methods available on the object.\n\n## Usage\n\n### Basic example\n\n```\nvar bindAll = require('bindall-standalone');\n\nvar object = {\n    foo: 10,\n    bar: function() {\n        return this.foo;\n    }\n};\n\nobject.bar(); // 10\n\nvar func = object.bar;\nfunc(); // undefined\n\nbindAll(object, 'bar');\nvar func = object.bar;\nfunc(); // 10\n```\n\n### Real-world example\n\n```\nvar bindAll = require('bindall-standalone');\n\nvar Foo = function() {\n    bindAll(this, 'onReady');\n\n    // mediator.on('ready', this.onReady.bind(this)); // Never going to be unbinded !\n    mediator.on('ready', this.onReady); // No need for explicit 'bind' now !\n};\n\nFoo.prototype.onReady = function() {\n    // mediator.off('ready', this.onReady.bind(this)); // That is sad, bro\n    mediator.off('ready', this.onReady); // Properly unbinded !\n};\n\n```\n\n## What is this\nIt used to be a standalone version of underscore's `_.bindAll()` function for IE9+ browsers.\nBut since bindAll goal is to provide a quick way to bind/unbind methods, and only that, I updated it to use a quicker, more compatible `bind` function.\n\nSee the [underscore source](http://underscorejs.org/docs/underscore.html) for reference.\n\nBasically, it avoids this use case:\n\n```\nmediator.on('foo', this.bar.bind(this));\nmediator.off('foo', this.bar.bind(this));\n// will never be unbinded because this.bar.bind(this) != this.bar.bind(this)\n```\n\n## Under the hood\nSince bindAll's only goal is to bind a method to its object context, the bind function can be written as:\n\n```\nfunction bind(func, context) {\n  return function() {\n    return func.apply(context, arguments);\n  };\n}\n```\n\nNo need for the modern `bind` function, no need for a polyfill.\nAnd it's a lot faster ! Check this [jsPerf case](http://jsperf.com/native-bind-vs-fast-bind).\n\n## Caveats\nThere is one significant thing to know: by binding a method on it's object context, it creates an instance-level method.\nCheck this [article](http://freshbrewedcode.com/jimcowart/2013/02/12/getting-into-context-binds/) and this [fiddle](http://jsfiddle.net/ayamflow/8WKvU/) for more info.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayamflow%2Fbindall-standalone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayamflow%2Fbindall-standalone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayamflow%2Fbindall-standalone/lists"}