Author: Not specified Language: javascript
Description: Not specified Timestamp: 2018-04-16 14:32:54 +0000
View raw paste Reply
  1. function MyObject(element) {
  2.     this.elm = element;
  3.  
  4.     element.addEventListener('click', this.onClick.bind(this), false);
  5. };
  6.  
  7. MyObject.prototype.onClick = function(e) {
  8.      var t=this;  //do something with [t]...
  9.     //without bind the context of this function wouldn't be a MyObject
  10.     //instance as you would normally expect.
  11. };
View raw paste Reply