7.ES5 some of the new common methods

ES5
 
Strict Mode
In addition to the normal operating mode, ECMAscript5 added a second mode of operation: "strict mode" (strict mode).
As the name suggests, this mode enables Javascript run under more stringent conditions.
 
The purpose of the "strict mode", mainly in the following:
    Eliminate unreasonable Javascript syntax, not rigorous place, reducing some of the bizarre behavior;
    Remove some of the insecurity code running, to ensure the safe operation of the code;
    Improve compiler efficiency, increase the operating speed;
    Pave the way for future new version of Javascript.
 
Enter "strict mode" sign: "use strict";
 
The "use strict"; on the first line of the script file, the whole script will be "strict mode".
<script>
   "use strict";
   console.log ( "This is the strict mode.");
</script>
 
The "use strict" on the first line of the body of the function, the entire function runs to "strict mode."
function strict(){
   "use strict";
   return "This is the strict mode.";
}
 
Strict mode has some limitations JS syntax and behavior:
Assignment to undeclared variable error directly, rather than becoming a global variable;
Prohibit this keyword refers to the global object;
Objects can not have the same name attribute (IEs);
Function parameters can not have the same name;
......
 
ES5 support case: ie9 +, chrome 19+, safari 5+, firefox 4+, opera 12+
 
 
ES5 new array of common methods
the indexOf () method returns a first position in the array of elements found, if it does not exist or -1
 
forEach () method for each element corresponding method
 
filter () method returns a new array, a new array element in the array is designated by checking all elements meet the conditions
 
After the map () method for each element of the array a certain operation, returns a new array
 
reduce () method takes a function as an accumulator, each value in the array (left to right) started to shrink, as a final calculated value
array.reduce(function(total, item, index, array), initialValue)
Returns the value of the initial value, or the end of the calculation: total
initialValue: initial value
 
 
String string
JavaScript is a character string '' or '' enclosed characters.
 
Your + spliced ​​between the strings.
 
Create a string:
was str1 = 'abc';
was STR2 = new String (ABC);
 
length- property returns the string length (number of characters)
str1.length; // 3
 
Can be accessed through the index of a character in a string: str1 [0], str1 [1]
 
String common API
API (Application Programming Interface, Application Programming Interface) is the number of pre-defined function
 
the toLowerCase () method of the entire string to lower case letters
 
toUpperCase () method to transfer the entire string uppercase
 
the indexOf () method returns the index of the first occurrence of the string neutron string, no matching -1
 
lastIndexOf () method returns the index of the last occurrence string neutron string, no matching -1
 
slice () method has been extracted from the portion of the character string, it returns the new string
was str1.slice size = (start, end);
slice () returns the substring of characters comprises at start, but does not include the character at the end
 
split () method of the string into a string array, a new array Returns
var str = str1.split ( 'delimiter', length);
The first argument specifies a code division, a second optional parameter, the returned array length
 
substr () method returns a substring starting at the specified position of the specified length
var str = str1.substr(start,length);
Parameters must start, the start position of a character, length parameter Alternatively, the length of the string interception
 
substring () method returns the string to the sub-string intermediary between two specified index
var str = str1.substring(start,end);
Character at the start contains, does not contain a character at the end
 
concat () method to combine two or more strings and returns a new string
 
the charAt () method returns the character specified index
 
replace () method is used to replace some of the character string by other character string is returned replacement
var newStr = str.replace ( 'abc', 'replacement abc');
 
the charCodeAt () method returns the character at the specified index value encoding unicode
 
String.fromCharCode (num1, num2, num3 ......) method returns a string code value according to a specified Unicode
var str = String.fromCharCode(65,66,67);// 'ABC'
 
 
ASCII, Unicode character sets and coding
 
:( referred to as the coded character set character sets, such as Unicode, ASCII)
Coded character set used to represent a coded value of a character position in the library table, this value is called the number of characters corresponding to character set encoding.
 
Only the first 127 letters are coded into the computer, which is the case letters, numbers and some symbols, the coding table is called ASCII.
 
ASCII code is mainly targeted at English, there are hundreds of languages ​​around the world, China has developed GB2312 coding, Japan enacted the Shift_JIS encoding, South Korea has developed Euc-kr encoding ...
 
Country has its own standards, will inevitably clash, the result is, in a multilingual mix of text, displayed will be garbled.
 
Unicode encoding all languages ​​are unified into a set encodings, so you do not have a garbage problem!
 
Unicode encoding is a big collection of its present size can accommodate more than one million symbols.
128 and ASCII encoding of Unicode as the beginning.
Coded character set Unicode, there is UTF-8, UTF-16, UTF-32 character encoding other.
 
Unicode character encoding table: http://www.chi2ko.com/tool/CJK.htm

Guess you like

Origin www.cnblogs.com/r-mp/p/11084813.html