I’m trying to get the prototype inside an event handler.
function Post(){
this.post;
this.deleteButton;
}
Post.prototype.delete = function(){
var OBJ = this;//this is not the prototype, instead it is the HTML element (deleteButton)
$(OBJ.container).remove();
}
Post.prototype.createPost = function(){
var OBJ = this;
OBJ.post = document.createElement('div');
OBJ.post.className = 'post'
OBJ.deleteButton = document.createElement('div');
OBJ.deleteButton.addEventListener('click', OBJ.delete, false);
}
Look at the comment section above. A delete handler is declared as a prototype method to Post. And I assign the delete handler to a delete button. The thing is that thisbecomes the HTML Element instead of the object prototype.
EDIT:
I also want to have the opportunity to remove the delete handler
Like this:
But
OBJis not the prototype, it refers to the instance.Update: If you want to remove it too, store a reference to it:
Somewhere else: