I have this es6 class:
class CommentsController {
constructor() {
this.$addCommentForm = $('.add-comment')
this.$addCommentButton = $('.add-comment input[type=submit]')
}
init() {
this.addCommentFormListener();
}
addCommentFormListener() {
this.$addCommentButton.on('click', function(e) {
e.preventDefault();
let imageId = parseInt($(this).parents('ul').data('id'));
let inputText = $(this).parents('ul').find('.user-text').val();
let comment = new Comment(inputText, imageId);
debugger;
CommentsController.renderComment(comment, imageId)
});
}
renderComment(comment, imageId) {
let image = Image.all[imageId]
image.comments.push(comment)
$('#images').find(`ul[data-id=${imageId}] ul#comments-${imageId}`).append(`<li>${comment.text}</li>\n`);
}
}
The problem is that at the debugger, I want to call the renderComment function but I cannot because this
does not refer to the controller anymore. What can I do?