KnockoutTest
by Sean Xu
HTML
<script src="http://knockoutjs.com/downloads/knockout-3.0.0.debug.js"></script>
JavaScript
var vm;
(function(vm){
vm.User = function(){
function User(){
this.name = ko.observable('name');
this.initilize.apply(this,arguments);
};
User.prototype = {
initilize: function(){
this.name.subscribe(function(newValue){
alert("The person's current name is " + newValue);
});
this.name.subscribe(function(oldValue) {
alert("The person's previous name is " + oldValue);
}, null, "beforeChange");
}
};
return User;
}();
}(vm || (vm = {})));
var user = new vm.User();
user.name('sean');