lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

Client-side_ JavaScript.md (1937B)


      1 +++
      2 title = 'Client-side: JavaScript'
      3 +++
      4 # Client-side: JavaScript
      5 - interpreted, no compilation
      6     - interpreter is embedded in another app (browser)
      7 - scripts operate in document/browser
      8 - dynamically typed — untyped variables, typed values
      9 - objects
     10     - an object is a set of properties
     11     - no classes!
     12     - a property is a unique-name key:value pair
     13     - created with a constructor:
     14 
     15 		```js
     16 		var ob = new Object();
     17 		ob.testing = "test";
     18 		```
     19 
     20     - deleted with delete:
     21 
     22 		```js
     23 		delete ob.testing;
     24 		```
     25 
     26     - built in: window (browser window), document (page in window)
     27 - DOM API (Document Object Model)
     28     - by W3C recommendations
     29     - works with document tree
     30     - functions from JS are called through HTML attributes
     31     - can add noes, remove nodes, change attributes
     32 - Events
     33     - when should shit happen?
     34     - after page loads, while(forever) wait for event
     35     - predefined: click, mouseover, mouseon, mouseout, keypress, resize, scroll, etc.
     36     - write a function to respond to event, then subscribe/register/bind it
     37     - browser calls it when needed
     38     - event "bubbling": events execute from lowest node upwards
     39 - AJAX (more like AJAJ or whatever, not really XML anymore, but AJAX sounds cooler)
     40     - recipe (always the same)
     41 
     42         1. Make initial page
     43         2. Set up event handlers
     44 
     45         3. When called, handlers do magic (request new data from server over HTTP in XML/JSON/whatever)
     46 
     47             - asynchronous, execution continues all the time, there's no wait for the server
     48             - shitty using XMLHttpRequest, better with jQuery
     49     - fast, easier for users
     50     - weak browser integration (e.g. back button), low search engine indexing, accessibility, response time, security
     51     - same origin policy: requests to other sites will be blocked, unless the target site opts in explicitly
     52     - some AJAX calls return HTML, others JSON (originally XML)
     53 - libraries — jQuery