{ "id": "106888", "key": "ALOY-441", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2012-12-20T22:38:54.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [], "versions": [ { "id": "14770", "description": "Alloy 0.3.4", "name": "Alloy 0.3.4", "archived": false, "released": true, "releaseDate": "2012-12-14" } ], "issuelinks": [ { "id": "23798", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "106822", "key": "ALOY-438", "fields": { "summary": "Proxy off() function from Backbone is not working", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": null, "updated": "2018-03-07T22:25:53.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "12329", "name": "Runtime", "description": "Generic bucket for uncategorized runtime issues" } ], "description": "h2. problem\r\n\r\nThe bulk of this issue was resolved in ALOY-438, but there still remains a small circumstance where unexpected behavior might happen. If a developer uses function expressions (as opposed to function declarations) to create an event handler function for a markup event, they will not be able to manually trigger (or remove) that event handler until after the controller code has executed. This is because in the case of function expressions, the event handler code is not executed until _after_ the developer's controller code, when the function expression is actually defined.\r\n\r\nh2. example showing problem\r\n\r\nh4. index.xml\r\n{code:xml}\r\n\r\n \r\n\r\n{code}\r\n\r\nh4. index.js (using function expression)\r\n{code:javascript}\r\n// Function expression used to define handleClick. This will work just fine.\r\nvar handleClick = function() { \r\n // This will be successfully removed as this event will be fired some time\r\n // after this controller's code has been executed.\r\n $.win.off(\"click\",handleClick);\r\n};\r\n\r\n$.win.open();\r\n\r\n// This will not fire \"handleClick\" because when function expressions are used\r\n// the event handler is not created until _after_ the developer's controller code\r\n$.win.trigger(\"click\");\r\n{code}\r\n\r\nh4. index.js (using function declaration)\r\n{code:javascript}\r\n// With function declarations, the following code will work as expected\r\nfunction handleClick() { \r\n $.win.off(\"click\",handleClick);\r\n};\r\n\r\n$.win.open();\r\n$.win.trigger(\"click\");\r\n{code}\r\n", "attachment": [], "flagged": false, "summary": "Markup event handlers defined as function expressions can't manually be triggered til after controller code is executed", "creator": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [], "maxResults": 0, "total": 0, "startAt": 0 } } }