J
J
JIakki2015-11-19 22:52:13
Node.js
JIakki, 2015-11-19 22:52:13

How to get the this of a class in node.js?

There is a class:

#index.js
function DB() {
  this.token = 'token';
}

DB.prototype.getData = require('./get')

module.exports = new DB;

# get.js
module.exports = function () {
  var self = this;
  console.log(self.token) // как получить свойство класса?
  
}

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-19
@JIakki

JS doesn't have classes.
Object property. Since you wrote. You just have to call...

var foo = new DB();
foo.getData();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question