wrap-function

(javascript) what is the wrap function used for regarding event handlers?

I'm trying to understand why people use a wrap function for my event handlers. For example: Example.prototype.wrap = function(obj, method) { return function(event) { obj[method](event); } } Basically, what is wrap used for? Edit: From the example linked below, the code is: String.prototype.capitalize = String.prototype.c...

(javascript) why do i need to use a wrap function for event handlers?

I'm trying to understand why in the following code I need Dragger.prototype.wrap and why I can't just use the event handling methods directly: function Dragger(id) { this.isMouseDown = false; this.element = document.getElementById(id); this.element.onmousedown = this.wrap(this, "mouseDown"); } Dragger.prototype.wrap = func...