I have the following problem, I have a constructor function that will mount an object for me:
var companyConstructor = function Company(id, logo, name, language, primaryColor, secondaryColor, description, headOffice, serverInfo, serverAddress, publicUrl) {
if (false === (this instanceof Company)) {
return new Company();
}
this.id = id;
this.logo = logo;
this.name = name;
this.language = language;
this.primaryColor = primaryColor;
this.secondaryColor = secondaryColor;
this.description = description;
this.headOffice = headOffice;
this.serverInfo = serverInfo;
this.serverAddress = serverAddress;
this.publicUrl = publicUrl;
this.users = [];
};
And I also have a method in prototype
of this function that adds users to the object:
companyConstructor.prototype.add = function (data) {
var o = {
id: data.Id,
name: data.Name,
email: data.Email
};
return this.users.push(o);
};
Then I create an instance of this object and in the course of the screen I fill this object:
var company = new companyConstructor();
company
, it enters the function of add
of prototype
and an error because it does not find properties.
$.ajax({
url: '/api/company/',
dataType: 'json',
type: 'POST',
data: company,
success: function (data) {
},
error: function (xhr) {
console.log(xhr.status);
}
});
Because the add
function is inherited I did not think it would be triggered in the post, I think something is wrong, someone could explain it to me.