Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. MyObject = function ()
  2. {
  3. MyObject.initializeBase(this);
  4.  
  5. this._someProperty = null;
  6. };
  7.  
  8. MyObject.prototype = {
  9.  
  10. initialize: function()
  11. {
  12. // Init
  13. },
  14.  
  15. get_someProperty: function()
  16. {
  17. return this._someProperty;
  18. },
  19.  
  20. set_someProperty: function(value)
  21. {
  22. this._someProperty = value;
  23. },
  24.  
  25. doSomething: function ()
  26. {
  27. $('.some-class').each(function ()
  28. {
  29. $(this).click(this.doClick); // this.doClick is wrong
  30. });
  31. },
  32.  
  33. doClick: function ()
  34. {
  35. alert('Hello World');
  36. }
  37. };
  38.  
  39. var that = this;
  40.  
  41. doSomething: function ()
  42. {
  43. var instance = this;
  44. $('.some-class').each(function ()
  45. {
  46. $(this).click(instance.doClick);
  47. });
  48. },
  49.  
  50. doSomething: function ()
  51. {
  52. $('.some-class').each(function(_, node)
  53. {
  54. $(node).click(this.doClick); // this.doClick is right
  55. }.bind(this));
  56. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement