Mastering the jsfl: What is JS

Source: Internet
Author: User
Tags natural logarithm
Document directory
  • Ecmascript Basics
  • Ecmascript Operator
  • Ecmascript statement
  • Ecmascript Function
  • Boolean object
  • Number object
  • String object
  • Array object
  • Math object
  • Date object
  • Regexp object

The javascript interpreter in Flash uses Mozilla spidermonkey engine version 1.5. This version can be downloaded from the web site www.mozilla.org/js/spidermonkey/ (expired ?). Spidermonkey is one of the two Reference implementations of the Javascript language developed by mozilla.org. It is the same as the engine embedded in the Mozilla Browser.

 

You can use the ActionScript language to compile scripts that can execute actions in the Flash Player Environment (that is, during the playback of SWF files. The Flash javascript API can be used to compile a script for executing multiple actions in the Flash Creation environment (that is, when the Flash program is enabled. These two scripts help simplify the creation process. For example, you can write scripts to automatically execute repetitive tasks, add custom tools to the Tools panel, or add timeline effects.

Flash JavaScript APIs are designed to be similar to Macromedia Dreamweaver and Macromedia fireworks JavaScript APIs (designed based on the Netscape javascript API ). The Flash javascript API is based on the Document Object Model (DOM). This model allows you to use JavaScript objects to Access Flash documents. The Flash javascript API contains all the elements of the Netscape javascript API and flash Dom. This document describes the newly added objects and their methods and attributes. You can use any element of the local JavaScript language in the Flash script, but it is only valid for meaningful elements in the Flash document context.

In addition, the javascript API contains many methods, allowing you to combine JavaScript and custom C code for extension.

 

 

 

The following is a basic tutorial on ecmascript (JS core reference) extracted from w3school.

 

Ecmascript Basics

Ecmascript syntax

Java and ecmascript have the same key syntax features and are completely different. This section describes the ecmascript syntax in detail.
Ecmascript variable
This section describes how to declare and name variables, as well as some famous variable naming rules.
Ecmascript keywords
This section provides a complete list of ecmascript keywords.
Ecmascript Reserved Words
This section provides a complete list of reserved words for ecmascript.
Ecmascript Value
This section describes the original and reference values of ecmascript and the concept of the original type of ecmascript.
Original ecmascript type
This section describes the five primitive types of ecmascript: undefined, null, Boolean, number, and string.
Ecmascript type conversion
This section describes the type conversion methods provided by ecmascript and how to perform forced type conversion.
Ecmascript reference type
A reference type is usually called a class or an object. This section describes the predefined reference types of ecmascript.
Ecmascript Operator
Ecmascript unary operator
The unary operator has only one parameter, that is, the object or value to be operated. This section describes the simplest operator-unary operator in ecmascript.
Ecmascript bitwise Operator
Bitwise operators operate on the bottom layer of numbers. This section provides an in-depth description of integers and introduces various bitwise operators of ecmascript.
Ecmascript boolean operator
The boolean operator is very important. This section describes three types of boolean operators: not, and, and or.
Ecmascript multiplication Operator
This section describes the multiplication operators of ecmascript: multiplication, division, modulo operators, and their special behaviors.
Ecmascript addition Operator
This section describes the addition and subtraction operators of ecmascript and their special behaviors.
Ecmascript Relational operators
Relational operators perform comparison operations. This section describes how to compare Relational operators and how to compare strings and numbers.
Ecmascript and other operators
Equality operators are used to determine whether the variables are equal. Ecmascript provides two sets of equality operators: equal signs and non-equal signs, and full and non-full.
Ecmascript conditional Operators
This section describes conditional operators in ecmascript.
Ecmascript assignment operator
This section describes the value assignment operators in ecmascript.
Ecmascript comma Operator
This section describes the comma operator in ecmascript.
Ecmascript statement
Ecmascript if statement
The IF statement is one of the most common statements in ecmascript. This section describes in detail how to use the if statement.
Ecmascript iteration statement
An Iteration statement is also called a loop statement. This section describes four types of iteration statements provided by ecmascript.
Ecmascript label statement
This section briefly introduces the statements with tags.
Ecmascript break and continue statements
This section describes the differences between the break statement and the continue statement, and how to use it with a label statement.
Ecmascript with statement
The with statement is used to set the scope of code in a specific object. This section describes the usage of the with statement.
Ecmascript switch statement
The switch statement is the brother statement of the IF statement. This section describes the usage of the switch statement and its differences from the switch statement in Java.
Ecmascript Function
Ecmascript function Overview
This section describes the concept of functions, how ecmascript declares and calls functions, and how functions return values.
Ecmascript arguments object
This section describes the basic usage of this object, describes how to use the Length attribute to determine the number of parameters of a function, and simulate function overloading.
Ecmascript function object (class)
This section describes how to use the function class to create a function, and then describes the attributes and methods of the function object.
The following is a Boolean object of the JS core class.

Boolean indicates two values: "true" or "false ".

Syntax for creating a Boolean object:
New Boolean (value); // Constructor
Boolean (value); // conversion function parameter
The parameter value is the value stored by a Boolean object or converted to a Boolean value.

Return Value
When called as a constructor (with the new operator), Boolean () converts its parameters into a Boolean value and returns a Boolean object containing the value.
When called as a function (without the new operator), Boolean () only converts its parameters into an original Boolean value and returns this value.

Note: If the value parameter is omitted or set to, null, "", false, undefined, Or Nan, the object is set to false. Otherwise, set it to true (even if the value parameter is a string "false ").
Boolean Object Attributes

Attribute description
Constructor returns a reference to the Boolean function that creates this object.
Prototype enables you to add attributes and methods to an object.
Boolean object Method

Method description
Tosource () returns the source code of the object. -
Tostring () converts the logical value to a string and returns the result.
Valueof () returns the original value of the Boolean object.
Boolean Object Description
In JavaScript, a Boolean value is a basic data type. A boolean object is a Boolean object that packs a Boolean value. A boolean object is mainly used to convert a Boolean value to a string's tostring () method.

When the tostring () method is called to convert a Boolean value to a string (usually called implicitly by JavaScript), JavaScript internally converts the Boolean value to a temporary Boolean object, then, call the tostring () method of this object.

Number object

The number object is the packaging object of the original value.

Syntax for creating a number object:
VaR mynum = new number (value );
VaR mynum = Number (value); Parameter
The parameter value is the value of the number object to be created, or the value to be converted to a number.

Return Value
When number () and operator new are used as constructors, it returns a newly created number object. If the new operator is not used and number () is called as a function, it will convert its own parameter into an original value and return this value (if the conversion fails, returns Nan ).
Number Object Attributes

Attribute description
Constructor returns a reference to the number function that creates this object.
Max_value indicates the maximum number.
Min_value represents the smallest number.
Nan is a non-numeric value.
Negative_infinity is negative infinity. This value is returned when overflow occurs.
Positive_infinity is positive infinity. This value is returned when overflow occurs.
Prototype enables you to add attributes and methods to an object.
Number object Method

Method description
Tostring converts a number to a string and uses the specified base number.
Tolocalestring converts a number to a string in the local numeric format order.
Tofixed converts a number to a string, and the result has a specified number of digits after the decimal point.
Toexponential converts the object value into an exponential notation.
Toprecision format the number to the specified length.
Valueof returns the basic numeric value of A number object.
Number Object Description
In JavaScript, numbers are a basic data type. Javascript also supports the number object, which is the packaging object of the original value. When necessary, JavaScript will automatically convert between the original data and the object. In JavaScript, you can use the constructor number () to explicitly create a number object, although this is not necessary.

The constructor number () can be used directly as a conversion function instead of the new operator. When you call number () in this way, it will convert its parameter into a number, and then return the converted original value (or Nan ).

Constructors are usually used as placeholders for useful numeric constants, this useful numeric constant is the maximum number that can be expressed, the minimum number that can be expressed, positive infinity, negative infinity, and special Nan values. Note that these values are the attributes of the constructor number (), rather than the attributes of a single number object.

For example, the max_value attribute is correct:

VaR big = number. max_value, but this is incorrect:

VaR n = new number (2 );
VaR big = n. max_value as a comparison. Let's take a look at other methods of tostring () and number objects. They are the methods of each number object, not the methods of number () constructor. As mentioned above, when necessary, JavaScript will automatically convert the original value into a number object, and call the number method can be either a number object or a raw number value.

VaR n =;
VaR binary_value = n. tostring (2 );

String object

String object is used to process text (string ).

Syntax for creating a String object:
New String (s );
String (s); Parameter
The parameter S is the value to be stored in the string object or converted to the original string.

Return Value
When string () and the new operator are used as constructors, it returns a newly created String object, which stores the string representation of string s or S.

When you do not use the new operator to call String (), it only converts s to the original string and returns the converted value.
String object attributes

Attribute description
Constructor references the function used to create the object
Length String Length
Prototype allows you to add attributes and methods to an object
String object Method

Method description
Anchor () creates an HTML anchor.
Big () displays strings in a large font.
Blink () displays the flashing string.
Bold () displays strings in bold.
Charat () returns the character at the specified position.
Charcodeat () returns the Unicode encoding of characters at the specified position.
Concat () connection string.
Fixed () displays strings in typewriter text.
Fontcolor () uses the specified color to display strings.
Fontsize () uses the specified size to display the string.
Fromcharcode () creates a string from the character encoding.
Indexof () to retrieve strings.
Italics () uses italics to display strings.
Lastindexof () searches for strings from the back and forward.
Link () displays the string as a link.
Localecompare () compares two strings in a specific local order.
Match () finds the matching of one or more in-process expressions.
Replace () replaces the substring that matches the regular expression.
Search () searches for values that match regular expressions.
Slice () extracts the string segment and returns the extracted part in the new string.
Small () uses a small font size to display strings.
Split () splits the string into a string array.
Strike () uses strikethrough to display strings.
Sub () displays the string as a subscript.
Substr () extracts a specified number of characters from the start index number.
Substring () is used to extract the characters between two specified index numbers.
Sup () displays the string as a superscript.
Tolocalelowercase () converts the string to lowercase. --
Tolocaleuppercase () converts the string to uppercase. --
Tolowercase () converts a string to lowercase.
Touppercase () converts a string to uppercase.
Tosource () indicates the source code of the object. -
Tostring () returns a string. --
Valueof () returns the original value of a string object.
String object description
A string is a basic data type of JavaScript.

The Length attribute of the string object declares the number of characters in the string.

The string class defines a large number of string operations, such as extracting characters or substrings from a string, or retrieving characters or substrings.

It should be noted that JavaScript strings are immutable, and the methods defined by the string class cannot change the content of strings. A method like string. touppercase () returns a brand new string instead of modifying the original string.

In the earlier JavaScript Implementation of Netscape code base (such as Firefox implementation), the string behavior is like a read-only character array. For example, to extract the third character from string S, use s [2] instead of S. charat (2 ). In addition, when a for/in loop is applied to a string, it will enumerate the array subscript of each character in the string (but note that the Length attribute cannot be enumerated according to ecmascript standards ). Because the string array behavior is not standard, avoid using it.

Array object

Array objects are used to store multiple values in a single variable.

Syntax for creating an array object:
New array ();
New array (size );
New array (element0, element0, elementn );
Parameters
The parameter size is the expected number of array elements. The returned array. The length field is set to the value of size.

The element parameter. elementn is the parameter list. When these parameters are used to call the constructor array (), the elements of the newly created array are initialized to these values. Its length field is also set to the number of parameters.

Return Value
Returns the newly created and initialized array.

If no parameter is used when the constructor array () is called, the returned array is empty and the length field is.

When a constructor is called, only one numeric parameter is passed. The constructor returns an array with a specified number and an undefined element.

When other parameters call array (), the constructor initializes the array with the value specified by the parameter.

When a constructor is called as a function without the new operator, its behavior is exactly the same as that when the new operator is used to call it.
Array Object Attributes

Attribute description
Constructor returns a reference to the array function that creates this object.
Index
Input
Length setting or return the number of elements in the array.
Prototype enables you to add attributes and methods to an object.
Array object Method

Method description
Concat () connects two or more arrays and returns results.
Join () puts all elements of the array into a string. The elements are separated by the specified delimiter.
Pop () deletes and returns the last element of the array.
Push () adds one or more elements to the end of the array and returns a new length.
The order of elements in the array is reversed by reverse.
Shift () deletes and returns the first element of the array.
Slice () returns the selected element from an existing array
Sort () sorts array elements
Splice () deletes an element and adds a new element to the array.
Tosource () returns the source code of the object. -
Tostring () converts an array to a string and returns the result.
Tolocalestring () converts the array to a local array and returns the result.
Unshift () adds one or more elements to the beginning of the array and returns a new length.
Valueof () returns the original value of the array object

 

Math object

Math objects are used to execute mathematical tasks.

Use the attributes and method Syntax of Math:
VaR pi_value = math. Pi;
VaR sqrt_value = math. SQRT (15); Note: Math objects are not classes of objects as date and string, so there is no constructor math (), like math. A function like sin () is just a function, not a method of an object. You can call all attributes and methods of a math object without creating it.
Math Object Attributes

Attribute description
E returns an arithmetic constant E, that is, the base number of the natural logarithm (approximately 2.718 ).
The natural logarithm (approximately 0.693) returned by ln2 ).
The natural logarithm (about 2.302) returned by ln10 ).
Log2e returns the base-on logarithm of E (approximately equal ).
Log10e returns the base-on logarithm of E (approximately 0.434 ).
Pi returns the circumference rate (approximately 3.14159 ).
Sqrt1_2 returns the reciprocal (approximately equal to) of the return square root ).
The square root (approximately equal to) returned by sqrt2 ).
Math object Method

Method description
ABS (x) returns the absolute value of the number.
ACOs (x) returns the arc cosine of the number.
Asin (x) returns the arc sine of the number.
Atan (x) returns the arc tangent of X with a value between-PI/2 and PI/2 radian.
Atan2 (Y, x) returns the angle from the X-axis to the point (x, y) (between-PI/2 and PI/2 radian ).
The Ceil (x) logarithm is rounded up.
Cos (x) returns the cosine of the number.
Exp (x) returns the e index.
The floor (x) logarithm is deprecated.
Log (x) returns the natural logarithm of the number (Base E ).
Max (x, y) returns the highest values in X and Y.
Min (x, y) returns the lowest values in X and Y.
Pow (x, y) returns the Y Power of X.
Random () returns ~ Between.
Round (x) rounds the number to the nearest integer.
Sin (x) returns the sine of the number.
SQRT (x) returns the square root of the number.
Tan (x) returns the tangent of the angle.
Tosource () returns the source code of the object. -
Valueof () returns the original value of the math object.

Date object

The date object is used to process the date and time.

Syntax for creating a date object:
VaR mydate = new date () Note: The date object automatically saves the current date and time as its initial value.
Date Object Attributes

Attribute description
Constructor returns a reference to the date function that creates this object.
Prototype enables you to add attributes and methods to an object.
Date object Method

Method description
Date () returns the date and time of the current day.
Getdate () returns a day (1 ~) of a month from the date object ~).
Getday () returns a day (0 ~) of a week from the date object ~).
Getmonth () returns the month (0 ~) from the date object ~).
Getfullyear () returns the year from the date object in four digits.
Use the getfullyear () method instead of getyear.
Gethours () returns the hour (0 ~) of the date object ~).
Getminutes () returns the minute (0 ~) of the date object ~).
Getseconds () returns the number of seconds (0 ~) of the date object ~).
Getmilliseconds () returns the millisecond (0 ~) of the date object ~).
Gettime () returns the number of milliseconds from year to month to date.
Gettimezoneoffset () returns the minute difference between the local time and Greenwich Mean Time (GMT.
Getutcdate () returns the Day (1 ~) of the month from the date object according to the Universal Time ~).
Getutcday () returns the day of the week (0 ~) from the date object according to the Universal Time ~).
Getutcmonth () returns the month (0 ~) from the date object based on the universal time ~).
Getutcfullyear () returns the four-digit year from the date object based on the universal time.
Getutchours () returns the hour (0 ~) of the date object based on the universal time ~).
Getutcminutes () returns the minute (0 ~) of the date object based on the universal time ~).
Getutcseconds () returns the second (0 ~) of the date object based on the universal time ~).
Getutcmilliseconds () returns the millisecond (0 ~) of the date object based on the universal time ~).
Parse () returns the number of milliseconds from midnight, January 1, January 1, 1970 to the specified date (string.
Setdate () specifies a day (1 ~) of the month in the date object ~).
Setmonth () sets the month (0 ~) in the date object ~).
Setfullyear () sets the year (four digits) in the date object ).
Use the setfullyear () method instead of setyear.
Sethours () sets the hour (0 ~) in the date object ~).
Setminutes () sets the minute (0 ~) in the date object ~).
Setseconds () sets the second (0 ~) in the date object ~).
Setmilliseconds () sets the millisecond (0 ~) in the date object ~).
Settime () sets the date object in milliseconds.
Setutcdate () sets the Day (1 ~) of the month in the date object based on the universal time ~).
Setutcmonth () sets the month (0 ~) in the date object based on the universal time ~).
Setutcfullyear () sets the year (four digits) in the date object based on the universal time ).
Setutchours () sets the hour (0 ~) in the date object based on the universal time ~).
Setutcminutes () sets the minute (0 ~) in the date object according to the Universal Time ~).
Setutcseconds () sets the second (0 ~) in the date object based on the universal time ~).
Setutcmilliseconds () sets the millisecond (0 ~) in the date object based on the universal time ~).
Tosource () returns the source code of the object. -
Tostring () converts a date object to a string.
Totimestring () converts the time part of the date object to a string.
Todatestring () converts the date part of the date object to a string.
Use the toutcstring () method instead of togmtstring.
Toutcstring () converts a date object to a string based on the universal time.
Tolocalestring () converts a date object to a string based on the local time format.
Tolocaletimestring () converts the time part of the date object to a string based on the local time format.
Tolocaledatestring () converts the date part of the date object to a string based on the local time format.
UTC () returns the number of milliseconds from the year, month, and day to the specified date based on the universal time.
Valueof () returns the original value of the date object.

Regexp object

The Regexp object represents a regular expression, which is a powerful tool for matching string execution modes.

Direct amount syntax
/Pattern/attributes:
New Regexp (pattern, attributes); Parameter
The pattern parameter is a string that specifies the regular expression mode or other regular expressions.

The attributes parameter is an optional string that contains the attributes "g", "I", and "M". It is used to specify global matching, case-sensitive matching, and multi-row matching, respectively. Before ecmascript standardization, the M attribute is not supported. This parameter must be omitted if pattern is a regular expression rather than a string.

Return Value
A new Regexp object with the specified pattern and flag. If the pattern parameter is a regular expression rather than a string, the Regexp () constructor creates a new Regexp object with the same pattern and flag as the specified Regexp.

If Regexp () is called as a function instead of the new operator, it performs the same behavior as when it is called using the new operator. It only returns pattern when pattern is a regular expression, instead of creating a new Regexp object.

Throw
Syntaxerror-If pattern is not a valid regular expression, or attributes contains characters other than "g", "I", and "M", this exception is thrown.

Typeerror-If pattern is a Regexp object but the attributes parameter is not omitted, this exception is thrown.
Regexp Object Attributes

Attribute description
Whether the global Regexp object has a flag.
Whether the ignorecase Regexp object has flag I.
Lastindex is an integer that indicates the next matching character position.
Whether the multiline Regexp object has a flag M.
Source Text of the source regular expression.
Regexp object Method

Method description
Compile a regular expression in compile.
Exec retrieves the value specified in the string. Return the value found and locate it.
Test retrieves the value specified in the string. Returns true or false.
Methods for string objects that support regular expressions

Method description
Search retrieves the value that matches the regular expression.
Match finds the matching of one or more in-process expressions.
Replace replaces the substring that matches the regular expression.
Split splits the string into a string array.

 

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.