SteveSanderson/knockout — pull request #354 by ethersage (2012-03-01 09:55:25+00:00)
Title: Extending the Binding Context

It would be nice if in a custom binding you could extend the binding context with custom properties that can be read by sibling nodes (that are bound after your custom binding) and descendant nodes. This may have been partially covered in [this issue](https://github.com/SteveSanderson/knockout/pull/290) but I didn't totally understand if/how parentContext, bindingContext.createChildContext, or bindingContext.extend was exposed to the developer.

You might ask, why not just have your custom binding do something like this in the init:

```javascript
var context = ko.contextFor(element);
context.$foo = 'bar'
ko.applyBindingsToDescendants(context, element);
return { controlsDescendantBindings: true };
```
As illustrated is this [fiddle](http://jsfiddle.net/Bhywk/53/) (hopefully), you can see that there are times where you might not be able to do that (because you have sibling bindings that are also trying to control descendant bindings).

In general, it would be nice to be able to augment the sibling and descendant bindings without having to commit to completely controlling all of them (as in 'controlsDescendantBindings'). I see this as a good point of extensibility in the core: to augment the binding context. If you'd like, I can alter the code to protect $data, $root, etc. from overwrites.

I had a little trouble with the specs. Had 10 very applicable errors, but they existed before my changes. Also would probably need to write some new specs, which I could totally do, but might need some pointers as I'm somewhat new to specs.

Thanks.