Skip to content

Instantly share code, notes, and snippets.

@marocchino
Created October 4, 2011 01:18
Show Gist options
  • Save marocchino/1260696 to your computer and use it in GitHub Desktop.
Save marocchino/1260696 to your computer and use it in GitHub Desktop.
Function.prototype.intercept = function(callback) {
var underlyingObservable = this;
return ko.dependentObservable({
read: underlyingObservable,
write: function(value) { callback.call(underlyingObservable, value) }
});
};
viewModel.lastName = ko.observable("some initial value").intercept(function(value) {
// Only accepts strings of length < 20
if (value.length < 20)
this(value);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment