How to add a computed observable via prototype
HTML
<script src="http://knockoutjs.com/js/knockout-2.0.0.js"></script>
<div data-bind="text: fullDomainName">test</div>
JavaScript
function SiteModel(rootUrl, data) {
var self = this;
self.rootUrl = rootUrl;
self.DomainName = ko.observable(data.DomainName);
self.IsSubDomain = ko.observable(data.IsSubDomain);
self.fullDomainName = ko.computed(self.fullDomainName, self);
}
SiteModel.prototype.fullDomainName = function () {
if (this.IsSubDomain() && this.DomainName()) { // bombs out here with "self.IsSubDomain is not a function"
return this.DomainName() + ".myCompanyWebsite.com";
}
else {
return this.DomainName();
}
};
var temp = new SiteModel("someurl", { DomainName: "extraCool" });
ko.applyBindings(temp);