Содержание
- 2. Agenda JS in Browser Events Memory Closure [1] [2] [3] [4]
- 3. JavaScript in Browser
- 4. JavaScript in Browser BOM window DOM
- 5. Events
- 6. Description How JavaScript communicates with the world? In outline this mechanism works by next scenario: user
- 7. Event handling But JavaScript doesn't observe events by default. You should specify to your code what
- 8. Inline handling Imagine that we have some HTML-element, for example and we want to do some
- 9. Using of onevent attribute btn.onclick = action; The next way doesn't touch HTML. For adding event
- 10. Proper ways Previous way makes sense, but has some limitations. For example you can not use
- 11. Proper ways btn.removeEventListener(“click”, action); In IE: Also, you can unsubscribe from any event. In W3C: btn.detachEvent(“onclick”,
- 12. Bubbling and Capturing The third parameter of addEventListener is a phase of event processing. There are
- 13. Bubbling and Capturing Bubbling Capturing [1] [2] [3]
- 14. Event object For every event in the browser instance of Event object will be created. You
- 15. Event object Event object is supported in IE, too, but it’s located in object window and
- 16. Control of Default behavior Sometimes a default scenario of event processing includes some additional behavior: bubbling
- 17. Memory and Sandbox
- 18. Basic info Free space in browser sandbox is allocated for each variable in JavaScript. Sandbox is
- 19. Scope The scope is a special JavaScript object which was created by browser in the sandbox
- 20. Scope window_scope = { test: function, a: 10, b: 20 }; test_scope = { b: 40
- 21. Value-types and Reference-types Unfortunately some objects are too large for scope. For example string or function.
- 22. Memory cleaning The basic idea of memory cleaning: when function is finished, scope should be destroyed
- 23. Unreachable links An object is considered unreachable if it is not referenced from the client area
- 24. Unreachable links action_scope = { a: reference, b: reference }; … somewhere in heap … function
- 25. Closures
- 26. Closure FYI: if scope is an object and it is not deleted it is still reachable,
- 27. Example function getPi () { var value = 3.14; return function () { return value; };
- 29. Скачать презентацию