I have a wep app that uses both knockout.js and require.js libraries. Let’s say that I have a ‘User’ model and a ‘Customer’ model. I want the Customer model to inherit from User, so I now have the following code:
User.js
define(['knockout'], function(ko){
return function User(){
var self = this;
self.id = ko.observable();
self.firstname = ko.observable();
self.name = ko.observable();
};
});
Customer.js
define(['knockout', 'model/user'], function(ko, User){
return function Customer(){
var self = this;
self.address = ko.observable();
};
Customer.prototype = new User();
});
When I create a Customer with the following code:
var c = new Customer();
c.id(1);
c.firstname("John");
c.name("Doe");
c.address("Unknown");
Then I get the following error in the Chrome console:
Uncaught TypeError: Object #<Customer> has no method 'id'
When I set only the address property, I don’t see this error so I’m assuming that there is something wrong with the inheritance. Any help is very welcome.
The following line will never be executed because you use return before:
Update
customer.jsto this: