0.0.4 • Published 8 years ago

bind-function-tree v0.0.4

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

bind-function-tree

Binds functions inside object tree to the same context. Pass javascript object containing functions inside of it’s hierarchy and it will traverse them and bind to the specified context object.

It does not change the object passed to it

Usage example

import bindTree from 'bind-function-tree';
const tree = {
  handleExitClick() {
    console.log(this);
  },
  videoPlayer: {
    controls: {
      handlePlay() {
        console.log(this);
      }
    }
  }
}
const ctx = {foo: 'bar'};

bindTree(tree, ctx);

This binds all the functions(handleExitClick, handlePlay) inside tree object to the ctx. Output of both console.log calls would be {foo: 'bar'}.

Compatibility

For now it depends on Object.keys and Array.prototype.forEach to work.

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago