Knockout notification valueToNotify behavior
Knockout notification callbacks receive valueToNotify if callbackTarget not supplied, but don't receive it when there is a callbackTarget.
HTML
<script src="https://github.com/downloads/SteveSanderson/knockout/jquery.tmpl.js"></script>
<script src="https://github.com/SteveSanderson/knockout/raw/master/build/output/knockout-latest.debug.js"></script>
<div id="console">
<h2>Log</h2>
<div id="log"></div>
</div>
CSS
#console {
margin-top: 2em;
padding: 0.2em;
background: #eeeeff;
}
#console button {
float: right;
}
#log {
clear: both;
font: 8pt monospace;
}
JavaScript
var observable = ko.observable('initial value');
var target = new Object();
observable.subscribe(function(notifiedValue) {
log("notify without target received " + notifiedValue);
});
observable.subscribe(function(notifiedValue) {
log("notify with target received " + notifiedValue);
}, target);
observable('new value');
///////////////////////
function log(message) {
$("#log").append(document.createTextNode(message)).append("<br/>");
}
function clearLog() {
$("#log").empty();
}