I have a function in costructor to load some data. Can I use constructor to initialize itself on success load?
function User(userId, fullName = '', email = '') {
this.userId = iserId;
this.fullName = fullName;
this.fullName = email;
this.loadUser = function(url) {
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
data: {
userId: this.userId
},
success: function(data) {
this(this.userId, data.user.fullName, data.user.email); //???????????????
},
});
}
}
let user = new User(123);
user.loadUser('myUrl');