2
I have the following problem, I have a construction function that will assemble 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 adding 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();
The problem is that when I give a post by passing this object company
, he enters the function of add
of prototype
and makes a mistake because it does not find the properties.
$.ajax({
url: '/api/company/',
dataType: 'json',
type: 'POST',
data: company,
success: function (data) {
},
error: function (xhr) {
console.log(xhr.status);
}
});
Because of the function add
inherited not thought she would be shot in the post, I think something is wrong, someone could explain me.
Uncaught TypeError: Cannot read property 'Id' of undefined
He is unable to find the propertyId
that is within the function.add
in the object prototype, it is this error that is giving in the console.– fbadaro