I am trying to create a custom binding that wraps an existing binding, namely the "with" or "foreach" bindings that are built into Knockout.
Unfortunately in doing so I get the following error: Uncaught TypeError: Cannot call method 'createChildContext' of undefined from knockout-latest.debug.js:3060 (the problem also exhibits on version 2.1.0).
I have reproduced the exception on jsFiddle, with Google Chrome 21.0.1180.57.
The custom binding is simply defined as follows:
ko.bindingHandlers.myWith = {
init: function(element, valueAccessor, allBindings, viewModel) {
// do things
return ko.bindingHandlers.with.init(element, valueAccessor,
allBindings, viewModel);
},
update: function(element, valueAccessor, allBindings, viewModel) {
return ko.bindingHandlers.with.update(element, valueAccessor,
allBindings, viewModel);
}
};
One would expect to be able to "wrap" the existing bindings with a simple handler in the form above, much like it is discussed in this article.