In JavaScript, it's pretty easy to intercept any method call because you can just modify the object. Thus you can replace ko.applyBindings
with your own function that does whatever you want (before or after you call the original):
ko.applyBindings = (function(original) {
return function () {
original.apply(this, arguments);
alert('ko.applyBindings called');
};
})(ko.applyBindings);
http://jsfiddle.net/mbest/4a2vK/
NOTE: This method will behave differently between the debug and release versions of Knockout. Knockout uses ko.applyBindings
internally for the template
binding, and when using the release version, it will always call the internal ko.applyBindings
function, whereas in the debug version, it will call our replacement function.