Improving Function.prototype.bind

Andrea Giammarchi andrea.giammarchi at
Thu Jan 5 08:46:33 PST 2012

all the time since I widely use private methods and I reuse them per each
created instance of a specific "class"

The boundTo() approach would make the method still private, immutable out
there, and reusable per each instance/object I need.

// stupid useless example ... just as concept
var Counter = (function () {
  // private
  function increase() {

  function Counter() {
    // none out there should be able to retrieve the bound function
    document.addEventListener("click", this.boundTo(increase), false);
  Counter.prototype.age = 0;
  Counter.prototype.destroy = function () {
    // so that only this class scope can control things and nobody else
    document.removeEventListener("click", this.boundTo(increase), false);
  return Counter;

Last, but not least, I do duck typing and I often borrow methods around for
smaller common tasks

Best Regards,
    Andrea Giammarchi

On Thu, Jan 5, 2012 at 5:11 PM, Axel Rauschmayer <axel at> wrote:

> that would not solve much 'cause you can bind a function to a single
> object and no more.
> Isn’t that the most frequent use case? Do you have examples where you bind
> the same function to several objects?
> --
> Dr. Axel Rauschmayer
> axel at
> home:
> twitter:
> blog:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list