j avascript j jp p resentation n.
Skip this Video
Loading SlideShow in 5 Seconds..
J avaScript J JP P resentation PowerPoint Presentation
Download Presentation
J avaScript J JP P resentation

J avaScript J JP P resentation

166 Vues Download Presentation
Télécharger la présentation

J avaScript J JP P resentation

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. JavaScriptJJPPresentation Jeff Watson Web & Internet Programming Group

  2. JavaScript Origins • JavaScript was developed by Brendon Eich of Netscape in early 1995, who is currently the Chief Technology Officer of the Mozilla Corporation. • First called Mocha, named LiveScript to showcase the dynamic nature of the scripting language. • December 4, 1995 - Sun Microsystems and Netscape collaborated and renamed LiveScript "JavaScript“. • Possibly named to capitalize on Java, an unrelated language which was quickly becoming popular with internet developers.

  3. Beware of Impostors • When JavaScript was released in March of 1996, Microsoft quickly introduced VBScript (initially only worked on Windows PCs), then JScript on July 16 1996. This was essentially their own version of JavaScript, which initially only worked with IE 3.0. • Most JavaScript developers simply checked for Netscape, ignoring IE. After Mozilla was recognized as a widespread browser, programmers created scripts for it, prompting other browsers to declare themselves as Mozilla when opening these pages, even though they were different browsers. • Netscape wanted standardization and submitted JavaScript to ECMA (European Computer Manufacturer's Association) which produced the ECMA-262 specification in June 1997. • ECMAScript is often used as a synonym for JavaScript and JScript, the two prevailing dialects, but Microsoft has stated that JScript does NOT conform to ECMA Standards. Said to be developed as a compromise between Microsoft and Sun, JavaScript creator Brendon Eich was quoted as saying that "ECMAScript was always an unwanted trade name that sounds like a skin disease."

  4. Revisions • The ECMA standard has released 2 revisions after the initial release, with a third in the works. • Edition 2 added small revisions to conform to ISO/IEC standards. • The third edition added regular expressions, better string handling, new control statements, try/catch exception handling, tighter definition of errors, formatting for numeric output and other enhancements. • The fourth edition will correspond to JavaScript 2.0, and introduce classes, structural types, packages and namespaces, static typing, generators and iterators, algebraic data types and other small additions.

  5. JavaScript is NOT Java There are several main differences: • Java is used to create standalone applications, while JavaScript is text which needs to be embedded into HTML. • Java is a much larger and more complicated language, with many more built-in functions and objects, as well as several libraries to support it. JavaScript is a much smaller set of built-in functions and objects used for simple internet applications. • Java is strongly typed (type-checking at compilation, JavaScript is dynamically typed (type-checking performed at run-time). • Array indices are not checked for validity (required in Java). • Although it supports instances of ADTs (objects), JavaScript does not support inheritance nor dynamic binding of method calls to methods, so it is not a true object-oriented language. • Java doesn’t have global functions due to OOP limitations, while they are used regularly in JavaScript code.

  6. Functionality • The first main draw for JavaScript was the incorporation of images properties, such as being able to click on various parts of an image with varying results. • The other main feature was that JavaScript could easily spawn new windows, enabling new information to be presented without navigating away from the main page. This caused many annoying pop-up ads when the internet was becoming popular in the United States. • JavaScript is embedded directly into HTML, and enables programmers to put static control structures as well as dynamic code into web pages. • The scripts would be run on the client’s machine rather than a server so that valuable information on the server could be more easily protected. • JavaScript works easily with HTML forms as well as alongside several other internet programming languages, and it is a simple way to accept and manipulate user input.

  7. Dynamic Features • Types are associated with values, not variables. Variables can be bound to several types of values throughout the course of a script. • Objects are instantiated as associative arrays, which lets programmers bind methods and variables to them whenever they decide it is necessary. • JavaScript is interpreted, not compiled. The only way to test code is by running it, and this is the only time that errors can be detected as well. • Although there are debuggers available, virtually all of them only work with the JavaScript code and since the script code works within HTML and alongside other languages, debugging can be very problematic.

  8. JavaScript vs. C++ • JavaScript is object-based, which is a limited version of an object oriented language, mainly due to its lack of inheritance and its prototype-based object handling. • JavaScript object properties can be added at any time and do not need to be pre-defined in an object declaration or constructor. • JavaScript does not support block-scoping, only global and function scoping. • JavaScript uses prototypes rather than classes. While they are not the same thing, it enables programmers to do many operations that are comparable to working with classes. • JavaScript relies on other applications, specifically a JavaScript-enabled web browser to run properly.

  9. Embedding JavaScript in HTML Embedding JavaScript into HTML is simple, and since JavaScript code is self-contained in <script> tags it allows for code from other languages and forms to be included in the page as well.

  10. Functions in JavaScript • Built-in functions are almost completely concerned with validating argument types which are commonly passed into functions or methods as well as converting variables to and from these types. • This includes specifics such as NaN(), infinity(), and undefined(), as well as functions for encoding and decoding data. • Functions can be created through several different techniques, and since JavaScript uses first-class functions, they are treated as objects. • Function objects have properties, and can be passed around and used just like any other object. • Functions can be declared within other functions. These are called “inner functions” and are the main idea behind closures in JavaScript.

  11. Function Declaration Example JavaScript has many different techniques for creating functions, and these show the objective nature that functions take on in the language.

  12. Closures • An expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression). • This generally happens when a function contains another function inside it, and has access to the outer function's variables. If the outer function returns and the inner function is still accessible to outside code, the inner function still has access to the outer function's variables. • This can result in security issues in some cases, but also has some practical applications.

  13. Closure Example The function getSecret() is declared within Guard(), which returns a reference to function getSecret(). This gives outside code access to an internal function, in turn giving the outside code access to the variables used within the inner function which, in this case, belong to function Guard(). Output (Along with a blank page):

  14. Built-in Objects • JavaScript’s collection of built-in objects is relatively small compared to other languages, but still provides the basic objects needed for most functional programming. • This includes mathematical objects, date/time objects and objective arrays. • Each type of built-in object is supported with several methods used to manipulate and display the data associated with them. • As stated before, JavaScript functions themselves are objects, and there are some other surprising objects such as strings and numbers which many programmers are used to seeing within built-in data types. This allows for elaborate string and number manipulation.

  15. Forms and JavaScript It is easy to utilize JavaScript in HTML forms, it adds functionality as well as plenty of ways to transfer and manipulate data.

  16. JavaScript allows HTML forms to be more dynamic in ways such as providing a simple means to manipulate and display input in an environment familiar to the modern programmer.

  17. Pop-Up Window Creation JavaScript’s popularity grew very quickly once advertisers realized that they could spawn windows with client-side code, resulting in massive amounts of pop-up advertisements, especially during early development of the language. Of course, spawning windows has very many practical uses as well.

  18. Window Creation/Manipulation Code See? Easy.

  19. Menus and Rollover JavaScript is able to recognize where images are clicked and can provide different procedures for different areas and images, providing an easy way to create internet menus.

  20. Rollover Illustrated The buttons darken as the mouse rolls over them, this helps to show users which objects are clickable and/or lead to links. Button A will link to and Button 2 will link to

  21. Current Usage • JavaScript has now become commonplace when creating online forms, buttons, menus, and other input methods, as well as ways to validate input. This is the dynamic nature of JavaScript. • Developers like JavaScript because it is easy to learn and keeps virtually all code executing on the client’s side, preventing security issues present in other internet languages. • Also, almost every web browser in the industry has developed a JavaScript debugger due to its growing popularity. • Future development will include the inclusion of classes and even more built-in functionality, and JavaScript 2.0 will provide developers with a myriad of new internet programming techniques.

  22. References • • Sebesta, Programming Languages. 8th Edition. • JavaScript with DOM Scripting and Ajax