0.0.4 • Published 8 years ago
bind-function-tree v0.0.4
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.