Translation: Chapter 1 of JavaScript authoritative guide (5th)

Source: Internet
Author: User
Document directory
  • 1.1. What is JavaScript?
  • 1.1. What is JavaScript?
  • 1.1.1. Javascript is not Java
  • 1.1.1. Javascript is not Java
  • 1.1.2. Javascript is not simple
  • 1.1.2. Javascript is not simple
  • 1.2. Versions of JavaScript
  • 1.2. Javascript version
  • 1.3. client-side Javascript
  • Client Javascript
  • 1.3.1. client-side JavaScript examples
  • 1.3.1 client JavaScript example

Statement: translation has only one purpose: learning purposes. If you have any copyright issues, please contact me in time.

This post divides the translation of Chapter 1 into two parts based on the length, which is the first part.

Chapter 1. Introduction to JavaScript Chapter 1 Introduction to Javascript

Javascript is an interpreted programming language with object-oriented (OO) capabilities. syntactically, the core JavaScript language resembles C, C ++, and Java, with programming constructs such as the if statement, the while loop, and the & operator. the similarity ends with this syntactic resemblance, however. javascript is a loosely typed language, which means that variables do not need to have a type specified. objects in Javascript map property names to arbitrary property values. in this way, they are more like hash tables or associative arrays (in Perl) than they are like structs (in C) or objects (in C ++ or Java ). the oo inheritance mechanic of JavaScript is prototype-based like that of the little-known language self. this is quite different from inheritance in C ++ and Java. like Perl, JavaScript is an interpreted language, and it draws inspiration from Perl in a number of areas, such as its regular-expression and array-handling features.

Javascript is an interpreted programming language with object-oriented (OO) capabilities. In terms of syntax, the core of the Javascript language is similar to that of C, C ++, and Java. Although it has program structures such as if statements, while loops, and & operators, however, it is only syntactically similar. Javascript is a weak type language, that is, the type of the variable does not need to be specified. Objects in javascript can map property names to arbitrary property values. At this point, it is more like a hash or associated array (in Perl) than a structure (in C) or an object (in C ++ or Java ). The Object-oriented Inheritance Mechanism in Javascript is prototype-based, which is similar to the self language. But it is very different from C ++ and Java inheritance. Java is an interpreted language (the same as Perl) and is inspired by the Perl language, such as regular expressions and array processing features.

The core JavaScript language supports numbers, strings, and boolean values as primitive datatypes. It also includes built-in support for array, date, and regular-expression objects.

The core JavaScript language supports numbers, strings, and Boolean primitive data types, as well as built-in support for objects such as arrays, dates, and regular expressions.

Javascript is most commonly used in Web browsers, and, in that context, the general-purpose Core is extended with objects that allow scripts to interact with the user, control the web browser, and alter the document content that appears within the web browser window. this embedded version of JavaScript runs scripts embedded within HTML web pages. it is commonly called client-side JavaScript to emphasize that scripts are run by the client computer rather than the web server.

Javascript is used most often in Web browsers. in its context, the general rendering core allows users to use scripts to expand and control objects in browsers, change the appearance of the Web browser window of the document content. The JavaScript embedded version runs the HTML web page embedded script. It is generally called client JavaScript to indicate that the script runs on the client computer rather than the web server.

The core JavaScript Language and Its built-in PES ypes are the subject of international standards, and compatibility between SS implementations is very good. parts of client-side JavaScript are formally standardized, other parts are de facto standards, and other parts are browser-specific extensions. cross-browser compatibility is often an important concern for client-side JavaScript programmers.

The core of the Javascript language and its built-in data types are international standardized projects, which make sense for compatibility across platforms. The javascript part of the client has been formally standardized, and the part of specific Browser Extensions is actually the standard. Cross-browser compatibility is one of the key points of attention for client JavaScript programmers.

This chapter is a high-level overview of JavaScript; it provides the background information you need before embarking on a study of the language. as motivation and introduction, it supports des some simple examples of client-side JavaScript code.

This chapter provides a high-level overview of JavaScript. It provides background information before getting started with language learning. There are also goals and introductions, including some client-side JavaScript sample code.

1.1. What is JavaScript? 1.1. What is JavaScript?

Javascript is the subject of a fair bit of misinformation and confusion. Before proceeding any further, it is important to debunk two common and persistent myths about the language.

Javascript is a very confusing topic. It is necessary to clarify two long-standing misunderstandings about the language before further research into it.

1.1.1. Javascript is not java1.1.1. Javascript is not Java

One of the most common misconceptions about Javascript is that it is a simplified version of Java, the programming language from Sun Microsystems. other than incomplete syntactic reseance ance and the fact that both Java and javascript can provide executable content in Web browsers, the two ages are entirely unrelated. the similarity of names is purely a marketing ploy by Netscape and Sun (the language was originally called livescript; its name was changed to JavaScript at the last minute ). however, JavaScript can, in fact, script Java (see chapters 12 and 23 ).

The most common misunderstanding of JavaScript is that it is a lite version of Sun Microsystem's Java programming language. However, apart from the syntax that is not completely similar and provides executable content for Web browsers, the two are completely irrelevant. Similar names are just the means of marketing (the language was originally called livescript, but was renamed JavaScript at the last time ). But there is actually script Java (See Chapter 12th and Chapter 23rd ).

1.1.2. Javascript is not simple1.1.2. Javascript is not simple.

Because Javascript is interpreted instead of compiled, it is often considered a scripting language instead of a true programming language. the implication is that scripting languages are simpler and that they are programming languages for nonprogrammers. the fact that JavaScript is loosely typed does make it somewhat more forgiving for unsophisticated programmers. and define web designers have been able to use JavaScript for limited, cookbook-style programming tasks.

Javascript is interpreted rather than compiled, so it is generally considered as a scripting language rather than a real programming language. The scripting language is generally regarded as a very simple, non-programmer programming language. But in fact, the loose types of JavaScript allow non-class programmers to write flexibly but not properly. Many Web designers can use JavaScript to execute limited programming tasks.

Beneath its thin veneer of simplicity, however, JavaScript is a full-featured programming language, as complex as any and more complex than some. programmers who attempt to use JavaScript For nontrivial tasks often find the process frustrating if they do not have a solid understanding of the language. this book documents JavaScript comprehensively so that you can develop a sophisticated understanding. if you are used to cookbook-style JavaScript tutorials, you may be surprised at the depth and detail of the chapters ahead.

Javascript is not that simple. It is a fully-featured programming language. If a programmer does not have a solid understanding of the usage of the Javascript language, he will find the progress difficult when executing complicated tasks. This book provides a comprehensive understanding of JavaScript. If you are using a recipe-based JavaScript tutorial, you will be interested in the depth and details of this chapter.

1.2. Versions of javascript1.2. JavaScript version

Like any new technology, JavaScript evolved quickly when it was new. previous editions of this book extends ented this evolution version by version, explaining exactly which language features were introduced in which version of the language. at the time of this writing, however, the language has stabilized and has been standardized by the European computer manufacturer's association, or ECMA. [*] implementations of this standard include the Javascript 1.5 interpreter from Netscape and the Mozilla Foundation, and the JScript 5.5 interpreter from Microsoft. any web browser newer than Netscape 4.5 or Internet Explorer 4 supports the latest version of the language. as a practical matter, you are unlikely to encounter a noncompliant interpreter.

Like any new technology, JavaScript updates are growing fast. The first few editions of this book have gone through version iterations. The features of each version of this language are described in detail. When writing this book, the language became stable and standardized by the European Computer Industry Association (or ECMA) [Note 1. The implementation scheme of this Standard includes the Javascript 1.5 interpreter of Netscape and Mozilla fund, and the JScript 5.5 interpreter of Microsoft. All Web browsers updated later than Netscape 4.5 or IE 4 support the updated version of the language. In fact, you do not want to encounter non-standard interpreters.

[*] The standard is ECMA-262, version 3 (available at http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf ).

Note 1: ECMA-262 V3 standard see http://www.ecma-international.org/publications/files/ecma-st/ECMA-262.pdf

Note that the official name of the language, according to The ECMA-262 standard, is ecmascript. but this awkward name is normally used only when making explicit reference to the standard. technically, the name "JavaScript" refers only to language implementations from Netscape and the Mozilla Foundation. in practice, however, everyone callthe language JavaScript.

The official name of the language is known as ecmascript according to ECMA-262 standards. However, this poor name is generally used only when you want to view details. Technically, "JavaScript" only refers to the language implementation in Netscape and Mozilla. In practice, the language is called JavaScript.

After a long period of stability for Javascript, there are now some signs of change. the Firefox 1.5 Web browser from the Mozilla Foundation between des a new javascript interpreter with the version number 1.6. this version includes des new (nonstandard) array manipulation methods described in section 7.7.10, as well as support for E4X, which is described next.

After the Javascript version is stable, there have been some changes. Mozilla's Firefox 1.5 Web Browser contains the javascript interpreter for version 1.6. This version includes a new array processing method (see section 7.7.10) and supports the next generation of E4X.

In the addition to the ECMA-262 specification that standardizes the core JavaScript language, ECMA has released another JavaScript-related standard. ECMA-357 standardizes an extension to JavaScript known as E4X, or ecmascript for XML. this extension adds an XML datatype to the language along with operators and statements for manipulating XML values. at the time of this writing, E4X is implemented only by JavaScript 1.6 and Firefox 1.5. e4X is not supported ented formally in this book, but Chapter 21 has des an extended introduction in tutorial form.

In addition to the Javascript language's core standardized ECMA-262 specification, there is another ECMA-357 standard related to JavaScript. It standardizes E4X (ecmascript for XML. It adds the XML data type (datatype) to the language and operates the XML value in combination with the operation statement and declaration language. In this book, E4X is only implemented in Javascript 1.6 and Firefox 1.5. The content of E4X is described in chapter 1 of this book as a tutorial.

Proposals for a fourth edition of The ECMA-262 specification, to standardize JavaScript 2.0, have been on the table for a number of years. these proposals describe a complete overhaul of the language, including strong typing and true class-based inheritance. to date, there has been little progress toward standardization of JavaScript 2.0. nevertheless, implementations based on draft proposals include Microsoft's JScript. net Language and the ActionScript 2.0 and ActionScript 3.0 versions ages used in the Adobe (formerly Macromedia) Flash Player. at the time of this writing, there are signs that work on JavaScript 2.0 is resuming, and the release of JavaScript 1.6 can be seen as a preliminary step in this direction. any new version of the language is expected to be backward-compatible with the version specified ented here, of course. and even once JavaScript 2.0 is standardized, it will take a few years before it is universally deployed in Web browsers.

Version 4th of The ECMA specification is a proposal to standardize JavaScript 2.0 over the years. These proposals describe a complete and improved language that includes strong types and a true class-based Inheritance Mechanism. So far, standardization of JavaScript 2.0 has taken a small step forward. Microsoft's JScript. Net Language and the ActionScript 2.0 and 3.0 languages used in Adobe (formerly Macromedia) Flash players are implemented based on draft proposals. While writing this book, JavaScript 2.0 is still under discussion, and the release of JavaScript 1.6 has given directions. Every new version of the language must be backward compatible, or even the Javascript 2.0 standard. In recent years, JavaScript 1.6 has been widely deployed in Web browsers.

1.3. client-side JavaScript client Javascript

When a javascript interpreter is embedded in a Web browser, the result is client-side JavaScript. this is by far the most common variant of JavaScript; when most people refer to Javascript, they usually mean client-side JavaScript. this book includes ents client-side JavaScript, along with the core JavaScript language that client-side JavaScript incyclates.

When the javascript interpreter is embedded into the web browser, it is the client JavaScript. This is the most common JavaScript variant so far. When Javascript is mentioned, it usually refers to client JavaScript. The client Javascript in this book is confused with the core of the Javascript language.

Client-side JavaScript combines the scripting ability of a javascript interpreter with the Document Object Model (DOM) defined by a Web browser. documents may contain in JavaScript scripts, and those scripts can use the Dom to modify the document or control the web browser that displays the document. put another way, we can say that client-side JavaScript adds behavior to otherwise static Web content. client-side Javascript is at the heart of web development techniques such as DHTML (see chapter 16) and ubuntures such as Ajax (See Chapter 20 ). the introduction to Chapter 13 has des an overview of the specified capabilities of client-side JavaScript.

The client JavaScript combines the Javascript script programming capability with the DOM defined in the Web browser. Documents can contain JavaScript scripts that can be used to modify documents or control the display of documents in a web browser. That is to say, the client JavaScript adds an additional behavior layer to the static Web content layer. It is the key point of web development technology (such as DHTML (see chapter 16th) and framework structure (such as Ajax (See Chapter 20th )). Section 13th provides an overview of various aspects of client-side JavaScript.

Just as the ECMA-262 Specification defines a standard version of the core JavaScript language, the World Wide Web Consortium (W3C) has published a DOM specification that standardizes the features a browser must support in its dom. (You'll learn much more about this standard in chapters 15, 16, and 17 .) the core portions of the W3C Dom standard are well supported in all major web browsers. one notable exception is Microsoft Internet Explorer, which does not support the W3C standard for event handling.

Just as the ECMA-262 Specification defines a standardized version of the Javascript language core, W3C has also released a DOM specification that standardizes the features that browsers must support in their Dom. We will learn more about the content in Chapter 15th, 16, and 17. Although the core part of W3C Dom standards has been supported by all mainstream Web browsers, it should be noted that Microsoft's IE does not support W3C standard event processing.

1.3.1. client-side JavaScript examples1.3.1. client JavaScript example

When a web browser is augmented with a javascript interpreter, it allows executable content to be distributed over the Internet in the form of JavaScript scripts. example 1-1 shows what this looks like: it is a simple JavaScript program, or script, embedded in an HTML file.

In a web browser embedded with the javascript interpreter, executable content can be distributed to the Internet in the form of JavaScript scripts. Example 1-1 is a simple JavaScript Program (or script) in an HTML file ).

When loaded into a javascript-enabled browser, this script produces the output shown in Figure 1-1.

After loading in the JavaScript-enabled browser, the output result is 1-1.

Figure 1-1. A web page generated with JavaScript

Figure 1-1 web page generated using JavaScript

As you can see in this example, the <SCRIPT> and </SCRIPT> tags are used to embed Javascript code in an HTML file. i'll describe the <SCRIPT> tag further in chapter 13. the main feature of JavaScript demonstrated by this example is the use of the document. write () method. [*] This method is used to dynamically output HTML text into an HTML document while it is being loaded into the browser.

In this example, the <SCRIPT> and </SCRIPT> labels embed Javascript code into an HTML file. We will learn more about the <SCRIPT> label in Chapter 13th. This example shows an application of the document. Write () method (note 1), a major function of JavaScript. This method is used to dynamically output HTML text to the loaded browser and display it in the HTML document.

[*] "Method" is the OO term for function or procedure; you'll see it used throughout this book.

NOTE 1: The method is an object-oriented (OO) term, which refers to a function or process. It is often seen in this book.

Javascript can control not only the content of HTML documents but also the behavior of those documents. that is, a javascript program might respond in some way when you enter a value in an input field or hover the mouse over an image in a document. javaScript does this by defining event handlers for the document pieces of JavaScript code that are executed when a special event occurs, such as when the user clicks on a button. example 1-2 shows a simple HTML fragment that includes des an event handler executed in response to a button click.

Javascript not only controls the content of HTML documents, but also controls the behavior of these documents. That is to say, when you enter a value in the input area or move the mouse over the image in the document, the Javascript program can respond. Javascript is implemented by event processing in the document. Event Processing refers to the execution of some JavaScript code when a specific event occurs, such as clicking the button. Example 1-2 is a simple HTML, and the event processing is executed when the response button is clicked.

Example 1-2. An HTML button with a javascript event handler defined

Example 1-2 HTML buttons with JavaScript event processing Definitions

<button onclick="alert('You clicked the button');">Click here</button>

Figure 1-2 analyze strates the result of clicking the button.

Figure 1-2 shows the effect of clicking a button.

Figure 1-2. The javascript response to an event

The onclick attribute shown in Example 1-2 holds a string of JavaScript code that's executed when the user clicks the button. in this case, the onclick event handler callthe alert () function. as you can see in Figure 1-2, alert () pops up a dialog box to display the specified message.

In the previous example, The onclick attribute contains JavaScript code, which is executed when you click a button. The onclick event processing calls the alert () function. As shown in figure 1-2, the alert () dialog box displays the specified message.

Example 1-1 and 1-2 highlight only the simplest features of client-side JavaScript. the real power of JavaScript on the client side is that scripts have access to the content of HTML documents ENTs. example 1-3 contains a complete, nontrivial JavaScript program. the program computes the monthly payment on a home mortgage or other loan, given the amount of the loan, the interest rate, and the repayment period. it reads user input from HTML form fields, performs computations on that input, and then alters the document to display the results of the computation.

Examples 1-1 and 1-2 only use the simplest features of client JavaScript. The real power of JavaScript on the client is that the script accesses the content of HTML documents. Example 1-3 is a complete but not simple JavaScript program. It calculates the monthly spending on mortgages and other loans, and calculates the total amount of loans, interest rates, and loan repayment period. It reads user input in HTML form fields, computes them, and displays the calculation results in the document.

Translation: Chapter 1 of JavaScript authoritative guide (version 5th)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.