Call Function in Same Level Property in Javascript -
i have object this. want call encodetoken
inside callback in refreshtoken
property. can body me how javascript work this? thanks.
var obj = { encodetoken: function (obj){ var opt = {expiresinminutes: 1} return jwt.sign(obj, config.jwt_key, opt); }, decodetoken: function (token, callback){ jwt.verify(token, config.jwt_key, function (err, decoded){ callback(err, decoded); }); }, refreshtoken: function (token, callback) { this.decodetoken(token, function (err, decoded){ callback(err, howtocall.encodetoken()); }); }, };
refreshtoken: function (token, callback) { var self = this; this.decodetoken(token, function (err, decoded){ callback(err, self.encodetoken()); }); }
you can read great explanation here - see simple call
, as object method
chapters - or here.