As I work on developing the model layer for my AngularJS application, I came across some valuable advice on using functions to create objects. This source emphasizes the use of functions like:
function User(firstName, lastName, role, organisation) {
// Public properties, assigned to the instance ('this')
this.firstName = firstName;
this.lastName = lastName;
this.role = role;
this.organisation = organisation;
}
In attempting to implement a default constructor with no arguments in mind, here is an example:
function User() {
// Public properties, assigned to the instance ('this')
this.id = getNewId(); //special function that retrieves sequence from database
this.firstName = '';
this.lastName = '';
this.role = '';
this.organisation = getDefaultOrganization();
}
I believe this approach should suffice, but I do have reservations about explicitly setting fields like this.firstName = ''; I would prefer to simply declare the fields and let JavaScript runtime assign default values provided by JavaScript types.
If there was an existing AngularJS model framework available instead of creating one myself, it would certainly make me more content. While exploring options like BreezeJS, I remain cautious due to certain concerns. The website's layout seems offputting (despite its comprehensive documentation), lacking a sense of strong community and active development. Furthermore, as a user of Laravel for backend, the lack of current support for it raises doubts about compatibility.