I am describing properties in the constructor function but when I called the Server.request
method in index.js its not showing properties at
console.log(this)
it outputs {}
(empty object)
Constructor
function Server(){
if(!(this instanceof Server)) return new Server()
this.actions = { // accepted actions
login: {
post: [['email', 'username'], 'password']
},
register: {
post: 'name,surname,password,email,haveLicence,licenceKey'.split(',')
}
}
}
Request function
Server.prototype.request = (req /* express request object */)=>{
console.log(this) // {}
return new Promise((r,j)=>{
let action = (req.url.match(/[a-z\-]+/i) || [])[0]
if(!action) return r([400, 'NoAction']);
action = this.actions[action] // Cannot read property 'register' of undefined.
...
}