JS Advanced Tutorial 1

Source: Internet
Author: User

Data + operator + operation Flow = Language substance skeleton

The algorithm is the soul skeleton

The complete JavaScript implementation is made up of the following 3 different parts: ECMAScript, Document Object model, browser object model.

The core ECMAScript of JavaScript describes the syntax and basic objects of the language, andECMAScript is an important criterion . ECMAScript is just a description that defines all the properties, methods, and objects of the scripting language. Other languages can implement ECMAScript as a benchmark for functionality, and each browser has its own implementation of the ECMAScript interface , and this implementation is expanded.

  The DOM describes the methods and interfaces for handling Web page content;

The BOM describes the methods and interfaces that interact with the browser.

Adhesives: ECMAScript

JavaScript objects
    • JS Array
    • JS Boolean Basic
    • JS Date
    • JS Math
    • JS number Basic
    • JS String Basic Data type pseudo-object
    • JS REGEXP
    • JS Functions
    • JS Events
Browser Object
    • Window
    • Navigator
    • Screen
    • History
    • Location
HTML DOM Object
    • DOM Document
    • DOM Element
    • DOM Attribute
    • DOM Event

Web browsers are a hosting environment for ECMAScript, and ECMAScript can provide core scripting capabilities for different kinds of hosting environments.

What does ECMAScript prescribe outside of the browser?

To put it simply,ECMAScript describes the following:

    • Grammar
    • Type
    • Statement
    • Key words
    • Reserved words
    • Operator
    • Object

The DOM (Document Object model) is an application interface (API) for HTML and XML. The DOM will plan the entire page into a document composed of node hierarchies. Each part of an HTML or XML page is a derivative of a node. Consider the following HTML page:DOM creates a tree to represent the document, giving developers unprecedented control over the content and structure of the document. The DOM API makes it easy to delete, add, and replace nodes .

because there is no relevant BOM standard, each browser has its own BOM implementation. There are some de facto criteria, such as having a Window object and a navigation object, but each browser can define its own properties and methods for those objects or other objects.

Raw values and reference values

In ECMAScript, a variable can have two types of values, the original value and the reference value.

Original value
Simple data segments stored in stacks (stack), that is, their values are stored directly in the location where the variable is accessed.
Reference value
the object stored in the heap (heap), that is, the value stored at the variable is a pointer (point) to the memory of the storage object.

When assigning a value to a variable, the ECMASCRIPT interpreter must determine whether the value is a primitive type or a reference type. To do this, the interpreter tries to determine whether the value is one of the original types of ECMAScript, that is, Undefined, Null, Boolean, number, and String. Because the space occupied by these primitive types is fixed, they can be stored in a smaller memory area-the stack. This stores the values that facilitate quick lookup of variables. ECMAScript provides the typeof operator to determine whether a value is within a certain type of range. You can use this operator to determine whether a value represents an original type: if it is the original type, you can also determine which primitive type it represents.

The Undefined type has only one value, which is Undefined. When the declared variable is not initialized, the default value of the variable is undefined.

In addition to TypeOf, other operators can only be used on declared variables. When a function has no explicit return value, the return value is also "undefined".

Another type with only one value is null, and it has only one private value, NULL, which is its literal. The value undefined is actually derived from the value null, so ECMAScript defines them as equal. Although the two values are equal, they have different meanings. Undefined is a value that is assigned to a variable when it is declared but not initialized, and null is used to represent an object that does not already exist (this is briefly described when discussing the typeof operator). If the function or method is to return an object, the object returned is usually null when it is not found.

The interesting thing about ECMAScript's original values of Boolean values, numbers, and strings is that they are pseudo-objects, which means that they actually have properties and methods.

For example, to get the length of a string, you would use the following code:

var scolor = "Red"; alert (scolor.length);//Output "3"



Object objects have the following properties:
Constructor
a reference (pointer) to the function that created the object. For object objects, the pointer points to the original object () function.
Prototype
a reference to the object's prototype of the object. For all objects, it returns an instance of object by default.
each object is defined by a class and can be considered a recipe for an object . The class defines not only the interface (interface) of the object (the properties and methods the developer accesses), but also the internal work of the object (the code that makes the properties and methods function). both the compiler and the interpreter build the object based on the description of the class .

An object-oriented language requires the developer to provide four basic capabilities:

    1. Encapsulation-the ability to store relevant information (regardless of data or method) in an object
    2. Aggregation-the ability to store an object within another object
    3. Inheritance-the ability to get properties and methods of a class by another class (or classes)
    4. Polymorphism-Ability to write functions or methods that can run in multiple ways

ECMAScript supports these requirements and can therefore be viewed as object-oriented.

object creation and destruction occur during JavaScript execution, and understanding the meaning of this paradigm is critical to understanding the entire language.

There are three objects that can be created and used: local objects, built-in objects, and host objects.

Host Object

All non-local objects are host objects (host object), which is the object provided by the hosting environment implemented by ECMAScript.

All BOM and DOM objects are host objects.

ECMA-262 defines local objects (native object) as "objects provided by ECMAScript implementations that are independent of the hosting environment." In simple terms, a local object is a class defined by ECMA-262 (reference type). They include:

    • Object
    • Function
    • Array
    • String
    • Boolean
    • Number
    • Date
    • Regexp
    • Error
    • Evalerror
    • Rangeerror
    • Referenceerror
    • SyntaxError
    • TypeError
    • Urierror
Features of Keyword Thisthis

One of the most important concepts to master in ECMAScript is the use of the keyword this, which is used in the object's methods. The keyword this always points to the object that called the method

JS Advanced Tutorial 1

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.