javascript intro - object - function
HTML
<div>
<input text="John" id="nameTxt"/>
<button id="btn">Change it</button>
</div>
<br>
<p>Name: <span text="p.FullName()", id="msg"></span></p>
JavaScript
//person constructor
var Person = function() {
// manage 'this'
var self = this;
self.firstName = 'John';
self.lastName = 'Papa';
};
// create a person
var p = new Person();
p.FullName = ko.computed (function(){
return this.firstName + " " + this.lastName;
}p);
//extend the person with an age property
p.age = 21;
var displayName = function() {
$('#msg').text(p.changeMyName());
};
// display the name
displayName();
$('#btn').click(function() {
//change the name to Brad
p.changeMyName();
displayName();
});