Answer the question
In order to leave comments, you need to log in
Is the constructor correct?
I'm trying to make a constructor that I will create in a loop a certain number of times to work with different parameters, I did something like this:
const setUserMagager = (config) => {
init: () => {
this.client = new ClientUser();
this.clientManager = new ClientManager({
user: this.client
});
this.options = {
name: config.name,
key: config.key
};
this.cookies = [];
client.login(options);
this.viewer();
},
viewer: () => {
this.client.on('login', () => {
this.client.setLogin();
});
this.client.on('msg', (session) => {
serveSession(session);
});
this.clientManager.on('user', (data) => {
serveNewUser(data);
});
}
}
Answer the question
In order to leave comments, you need to log in
I don't understand the purpose of this entity, but it's not a constructor. The viewer method is named incorrectly because the name doesn't say anything about what the method does.
A constructor is when:
function SetUserManager(config) {
this.client = new ClientUser();
this.clientManager = new ClientManager({
user: this.client
});
this.options = {
name: config.name,
key: config.key
};
this.cookies = [];
client.login(options);
this.viewer();
}
SetUserMagager.prototype.viewer = function() {
this.client.on('login', () => {
this.client.setLogin();
});
this.client.on('msg', (session) => {
serveSession(session);
});
this.clientManager.on('user', (data) => {
serveNewUser(data);
});
}
class SetUserMagager {
constructor(config) {
this.client = new ClientUser();
this.clientManager = new ClientManager({
user: this.client
});
this.options = {
name: config.name,
key: config.key
};
this.cookies = [];
client.login(options);
this.viewer();
}
viewer() {
this.client.on('login', () => {
this.client.setLogin();
});
this.client.on('msg', (session) => {
serveSession(session);
});
this.clientManager.on('user', (data) => {
serveNewUser(data);
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question