{"action":"closed","issue":{"url":"https://api.github.com/repos/zurb/foundation/issues/6091","labels_url":"https://api.github.com/repos/zurb/foundation/issues/6091/labels{/name}","comments_url":"https://api.github.com/repos/zurb/foundation/issues/6091/comments","events_url":"https://api.github.com/repos/zurb/foundation/issues/6091/events","html_url":"https://github.com/zurb/foundation/issues/6091","id":51358476,"number":6091,"title":"Interchange - resize function Closure problem","user":{"login":"godseyn","id":10121864,"avatar_url":"https://avatars.githubusercontent.com/u/10121864?v=3","gravatar_id":"","url":"https://api.github.com/users/godseyn","html_url":"https://github.com/godseyn","followers_url":"https://api.github.com/users/godseyn/followers","following_url":"https://api.github.com/users/godseyn/following{/other_user}","gists_url":"https://api.github.com/users/godseyn/gists{/gist_id}","starred_url":"https://api.github.com/users/godseyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/godseyn/subscriptions","organizations_url":"https://api.github.com/users/godseyn/orgs","repos_url":"https://api.github.com/users/godseyn/repos","events_url":"https://api.github.com/users/godseyn/events{/privacy}","received_events_url":"https://api.github.com/users/godseyn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/zurb/foundation/labels/interchange","name":"interchange","color":"bfdadc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-12-08T22:02:35Z","updated_at":"2015-01-23T22:39:37Z","closed_at":"2015-01-23T22:39:37Z","body":"<b>Interchange</b>, function <I>resize</I>\r\nThe resize function uses the variable <b>passed</b> in a loop.  An anonymous function inside the loop references the variable <b>passed</b>, creating a closure.  Since the closure stores a reference to variable <b>passed</b>, it will always take on the last value assignment in the loop.\r\n\r\nSee:\r\n```javascript\r\n//snip ... in function resize of Interchange\r\nfor (var uuid in cache) {\r\n    if (cache.hasOwnProperty(uuid)) {\r\n          var passed = this.results(uuid, cache[uuid]);\r\n\r\n          if (passed) {\r\n            this.settings.directives[passed\r\n              .scenario[1]].call(this, passed.el, passed.scenario[0], function () {\r\n                if (arguments[0] instanceof Array) { \r\n                  var args = arguments[0];\r\n                } else { \r\n                  var args = Array.prototype.slice.call(arguments, 0);\r\n                }\r\n\r\n                //BAD: Variable passed takes on last value in loop all the time\r\n                passed.el.trigger(passed.scenario[1], args); \r\n              });\r\n          }\r\n     }\r\n}\r\n```\r\n\r\nThis greatly affects triggering the <b>replace</b> event for HTML partials.  The event will always be fired on the last element in the list."}}