Presentation is loading. Please wait.

Presentation is loading. Please wait.

Client-side processing in JavaScript.... JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays.

Similar presentations


Presentation on theme: "Client-side processing in JavaScript.... JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays."— Presentation transcript:

1 Client-side processing in JavaScript...

2 JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays form checking etc. –Netscape looking for an edge over Microsoft MS swamp market with free high-quality browsers how can Netscape sell browsers….?

3 JavaScript... Has nothing to do with Java –named for purely political/marketing purposes refers to a class of languages –a different instance for each browser version hugely non-standard –deliberately –becoming less of an issue for the future

4 variants JavaScript 1.0, 1.1, 1.2, 1.3 (?) –a Netscape trademark JScript 1.0,1.2 (1.3?) –a Microsoft trademark ECMAScript –(European Computer Manufacturers’ Association) –a standard is emerging (ECMA-262) will be ISO-16262

5 client-side paradigms document appearance and content browser control HTML form interaction user interaction client state read/write various others… –notably applet interaction

6 The basic model A general-purpose, fully-fledged programming language –actually quite a good one... Not inherently object-oriented –but OO style can be achieved “scripting” language –no real distinction - implementation detail –but - no “compilation” phase

7 Binding to pages insert html text during load –a tag is evaluated during document load –the identifier “document” binds to the loading document –is “good practice” currently but maybe dated… –avoids mixing HTML and script

8 The data model Normal mix of types and operators… “dynamic” object model var X = new Object() X.age = 27 X.name = "Fred" Largely untyped –dereference of non-field = UNDEFINED –dereference of UNDEFINED -> dynamic error Run-time environment is very flexible –Lacks safety!

9 Tricky programming… Software development is extremely tricky –Browsers are main test facility Behaviour is fickle…. –Errors may not be flagged Program may just halt execution –Hardly any support Eg “error line 93, character 17” (HMTL file) –No syntax checking Syntax error leads to run-time failure I have written, just for you, a syntax checker! –http://www.cis.strath.ac.uk/~richard/typescript/system/frames.html

10 Debug… Typically involves extensive use of “alert” function –Eg alert( “execution is here” ) Eg –var fred = new Object() fred.name = “Fred” document.write( fried.name ) alert( “execution is here” ) Nothing happens…

11 example load-time script The meaning of life is now = new Date(); document.write( 7 * 6 ); document.write( " in " ); document.write( now.getUTCFullYear() );.

12 evaluation after load The meaning of life is 42. function f( x ) { alert( x ); }

13 DHTML A run-time environment for JavaScript Allows scripts to access the document object model of the underlying HTML –Models include DOM Many changes to these objects are auto- refreshed in browsers (esp. IE5.0) –Code can easily change display

14 the programming environment document –the HTML currently displayed –Contains documentElement field The head of the DOM tree window –the OS window hosting the page navigator –the browser application being used screen –the physical monitor being used

15 Evaluation contexts client-side - evaluation with browsers –almost all current use server-side –still proprietary Netscape “livewire” server, Microsoft ASP framework embedded –source code of interpreters is freely available allowing scripts to be included in any framework

16 common example of abuse… function bringItBackAgain( ) { window.open( ”http://www.pornofilth.com" ); }

17 event handlers What is the meaning of life?

18 Cookies Outdated – DHTML contains persistent info in a more programmer-friendly form small grains of information that can be stored with the browser application –under the user’s control also –(may be disallowed) can preserve state between accesses –client details –dynamically generate different text for a previous visitor

19 Scope normal lexicographic scope applies within programs –local: var a = 1 –global: a = 1 Beware eg for( i = 0; …. ) ! default global scope is context-dependent –“document” in a browser functions are scoped like variables watch for dynamic interactions! –browser interface, global scoping

20 objects, syntax, etc Object-oriented behaviour can be built from basic components –1 st -class code, flexible objects, this binding –Mostly just need to know for using object eg standard libraries etc. for a full understanding, read –Essential JavaScript (Flanagan, O’Reilly) –ECMA standard definition check out Microsoft (msdn) web site


Download ppt "Client-side processing in JavaScript.... JavaScript history Motivations –lack of “dynamic content” on web pages animations etc user-customised displays."

Similar presentations


Ads by Google