I'm using es6 features and compile it with babel on nodeJs, but it seems that i'm unable to access to instance from another method
export default class TimeRouter {
router : Router;
path : string;
constructor(path:string='/api/v1/timerouter'){
this.router = Router();
this.path = path;
this.init();
this.timeRanges = {
'LAST_SEMESTER' : 6, //nb of months,
'LAST_12_MONTHS' : 12,
'LAST_TRIMESTER' : 4,
'LAST_YEAR' : 12
}
}
getTimeRanges(req: $Request, res:$Response): void {
console.log('Test ranges',this); //returns undefined
res.status(200).json(this.timeRanges);
}
init():void {
this.router.get('/',this.getTimeRanges)
}
}
With gulp-sourcemaps and gulp-babel, I get this gulp config :
gulp.task('scripts', () => {
return gulp.src('src/**/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build'));
});
It renders something like this :
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i 0 && arguments[0] !== undefined ? arguments[0] : '/api/v1/timerouter';
_classCallCheck(this, TimeRouter);
this.router = (0, _express.Router)();
this.path = path;
this.init();
this.timeRanges = {
'LAST_SEMESTER': 6, //nb of months,
'LAST_12_MONTHS': 12,
'LAST_TRIMESTER': 4,
'LAST_YEAR': 12
};
}
_createClass(TimeRouter, [{
key: 'getTimeRanges',
value: function getTimeRanges(req, res) {
console.log(this.timeRanges);
var ranges = this.timeRanges;
res.status(200).json(ranges);
}
}, {
key: 'init',
value: function init() {
this.router.get('/', this.getTimeRanges);
}
}]);
return TimeRouter;
}();
exports.default = TimeRouter;
//# sourceMappingURL=TimeRouter.js.map
Any ideas why I can't access to the current instance ?