JavaScript jjp presentation Jeff Watson



Yüklə 418,5 Kb.
tarix07.11.2018
ölçüsü418,5 Kb.
#78690


JavaScript JJP Presentation


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.



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."



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.



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.



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.



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.



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.



Embedding JavaScript in HTML



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.



Function Declaration Example



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.



Closure Example



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.



Forms and JavaScript





Pop-Up Window Creation



Window Creation/Manipulation Code



Menus and Rollover



Rollover Illustrated



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.



References

  • http://en.wikipedia.org/wiki/JavaScript

  • Sebesta, Programming Languages. 8th Edition.

  • JavaScript with DOM Scripting and Ajax



Yüklə 418,5 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə