I'm trying to create a custom module. I'm using prototype
to add additional methods. The module will have an event, in which I will have to access a method from the module with this
. The problem is, when I use this
from the events function
, this
is something else. It isn't the module.
How can I access the modules methods in the events function? (Or if there's a better way to do what I'm trying to do, then please let me know.)
function MyPlugin() {
this.hello = 'hello'
document.addEventListener('click', this.clicked);
}
MyPlugin.prototype.clicked = function(e) {
console.log(this.hello);
}
MyPlugin.prototype.someMethod = function() {
console.log(this.hello + ' someMethod');
};
var plugin1 = new MyPlugin();