{"id":5872,"date":"2014-04-07T23:40:19","date_gmt":"2014-04-07T23:40:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/javascript-oop-binding-method-to-event-handler-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-04-07T23:40:19","modified_gmt":"2014-04-07T23:40:19","slug":"javascript-oop-binding-method-to-event-handler-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/javascript-oop-binding-method-to-event-handler-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"Javascript OOP: binding method to event handler [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>You found the one hole in Javascript&#8217;s implementation of closures. (If you don&#8217;t know what closures are, don&#8217;t worry about it.)<\/p>\n<p><code>this<\/code> in Javascript references the object on which the function was called. So if you have an object with a property that happens to be assigned the value of a function, and you call that property, the <code>this<\/code> pointer references the object. It does not reference whatever <code>this<\/code> was where the function was created, nor does it reference the function itself.<\/p>\n<pre><code>var object = {};\nobject.myfunc = function() { console.log(this); } \/\/<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You found the one hole in Javascript&#8217;s implementation of closures. (If you don&#8217;t know what closures are, don&#8217;t worry about it.) this in Javascript references the object on which the function was called. So if you have an object with a property that happens to be assigned the value of a function, and you call [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5872","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5872"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5872\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}