I am using a build tool with ES6 support, and I have the following code:
function Message(subject, body) {
this.subject = subject;
this.body = body;
this.unread = true;
}
Message.prototype.markAsRead = function() {
this.unread = false;
}
export {Message};
Later in another file when I do this:
import {Message} from './application/Message.js';
var message = new Message("hey", "there");
message.markAsRead();
I get the following error inside of the markAsRead()
method:
Uncaught TypeError: Cannot set property 'unread' of undefined
A console log of this
inside that method return undefined
.
Is it the way I'm importing/exporting Message? Is it something deprecated in ES6? I don't have this problem when I write ES5 JS, but I figure it's something simple that I'm doing wrong.