Created
February 21, 2016 12:57
-
-
Save drawveloper/da741e7f8b6929ba098f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// View (a template) | |
<p>First name: <input data-bind=”value: firstName” /></p> | |
<p>Last name: <input data-bind=”value: lastName” /></p> | |
<h2>Hello, <span data-bind=”text: fullName”> </span>!</h2> | |
// ViewModel (diplay data… and logic?) | |
var ViewModel = function(first, last) { | |
this.firstName = ko.observable(first); | |
this.lastName = ko.observable(last); | |
// Knockout tracks dependencies automatically. | |
// It knows that fullName depends on firstName and lastName, | |
// because these get called when evaluating fullName. | |
this.fullName = ko.pureComputed(function() { | |
return this.firstName() + “ “ + this.lastName(); | |
}, this); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment