Chapter V reference type

  1. Object Type: Create a new operator or objects can be object literal way, using the object literal manner Object constructor does not call, can access the object by square brackets [Properties] or by dot notation access object properties;.
  2. Array type: Creating an array may be used or new operator array literal manner, can be removed or added to the end of the array elements by modifying the length property is the size of the target by accessing the array element at the array embodiment, if the size exceeds the length property the size of the original set is not set the default element is undefined. It has the following methods: ① detection array: determine a value in the end is not an array, Array.isArray (value), returns a Boolean value; ② conversion method: the array will inherit toLocaleString (), toString (), valueOf () method returns a string comma-separated, except that each entry toLocaleString toLocaleString call () method will array () method, toString () will call for each item in the array toString () method, to replace the separator, can use arrays example .join (string delimiter); replace delimiter Note: alert () function is a string parameter defaults, so calls toString () method in the background; ③ stack method: pop (parameter), push (parameter), POP returned item removed, the length of the array push return the modified; ④ queue method: shift (), unshift (), shift key can be removed in a front end of the array and return that, while the unshift () can be added in any of an array of entries distal later modified and returns the length of the array; ⑤ reordering method: reverse (), sort (), reverse is possible to reverse the order of the array elements, and sort () square Calls toString () method, each array element method to sort the items according to the comparison string, which thus need to add sort () method a comparison function, function compare (value1, value2) {if (value1 <value2) { return -1;} else if (value1> value2) {return 1;} else {return 0;}}; this sort can function as an argument to, of course, for pure array values, the comparison function may be employed return value1- to value2; ⑥ operation: example. concat (parameters), will be copied on the basis of the original array parameters on an array of add on to form a new array and returns a new array at the end of the array; examples .slice (start position, end position), by passing an array of start and end the value of the position, a return from the start position to the end position, but does not include a new end position of the array entry, if parameter is negative, the actual position of the + = array length parameter, the method further parameters can be inserted, instances .slice ( starting position, to delete the item number, insert item 1 ....), can be inserted into the specified item from a starting position, if you want to delete an item, the equivalent of replacing these items; ⑦ location method: character indexIOf (to look for to begin searching for a location), character lastIndexOf (you are looking for, start looking for the position), respectively, the position of the character is returned from the front end of the array and began to look for, find, otherwise return -1; ⑧ iterative method: 5 iterative method has two parameters, namely the scope of the object function and operation of the function, the function has three parameters, representing the value of the position, the item array item array, the array Object itself, every () function if each item is returned returns ture ture, some () if there is a return to entry ture, then return ture, filter (), returns a list of items composed ture value, forEach ( ) does not return a value, map () function returns the result of calling an array of; ⑨ merge method: reduce (), reduceRight (), these two methods will once through each item in the array, a traversing from the left, from a traversing the right, there are two parameters are merged based on the role of each array entry, and function as an initial value, function has four parameters, namely, the previous value, the current value of the index entry numbers, array object, the function return value as the next item of the first parameter function. From the starting position can be inserted into the specified item, if you want to delete an item, the equivalent of replacing these items; ⑦ location Method: indexIOf (the character you are looking for, start looking for positions), character lastIndexOf (you are looking for, start searching ), respectively, and start looking from the front end of the array, find the location of the character is returned, otherwise return -1; ⑧ iterative method: 5 iterative method has two parameters, namely the scope of the object function and operation of the function, function has three parameters, an array of values ​​representing the item, the item position array, an array of object itself, every () function if each item is returned returns ture ture, some () if there is a return to entry ture, return ture, filter (), returns a list of items composed ture value, forEach () does not return a value, map () returns an array of the result of calling a function; merge ⑨ method: reduce (), reduceRight (), the two the method will once through each item in the array, a traversing from left to start a traverse from the right, there are two parameters are normalized to the role of each item in the array as well as the function The initial value of the base function has four parameters, namely, the previous value, the current value of the index entry numbers, array object, this function will return the value of the first parameter as a function of the next item. From the starting position can be inserted into the specified item, if you want to delete an item, the equivalent of replacing these items; ⑦ location Method: indexIOf (the character you are looking for, start looking for positions), character lastIndexOf (you are looking for, start searching ), respectively, and start looking from the front end of the array, find the location of the character is returned, otherwise return -1; ⑧ iterative method: 5 iterative method has two parameters, namely the scope of the object function and operation of the function, function has three parameters, an array of values ​​representing the item, the item position array, an array of object itself, every () function if each item is returned returns ture ture, some () if there is a return to entry ture, return ture, filter (), returns a list of items composed ture value, forEach () does not return a value, map () returns an array of the result of calling a function; merge ⑨ method: reduce (), reduceRight (), the two the method will once through each item in the array, a traversing from left to start a traverse from the right, there are two parameters are normalized to the role of each item in the array as well as the function The initial value of the base function has four parameters, namely, the previous value, the current value of the index entry numbers, array object, this function will return the value of the first parameter as a function of the next item.
  3. Date Type: Use new Date () to create a date object constructor can pass directly date format string, the system automatically calls Date.parse () method of the date of the date converted to milliseconds, of course, to use Date. now () returns the current time can call this method, pay attention to the beginning of the month is zero, and methods of obtaining every minute of day, the day when the setting is based on, get / setFullYear / month / date / day / Hours / Minutes / Seconds / Milliseconds ( );
  4. RegExp Type: Grammar: / mode / flag has three flags: G (global matching) / I (case insensitive) / m (multi-line matching), all of which meta pattern characters ({} () + * ^ $. \? []) you need to escape, which is defined by a regular expression literal form, but also by new RegExp ( "model", "string sign") to create a regular expression metacharacters need to double escape because the string is passed, Note: use the constructors and literal expression to create regular expressions creates a new instance; instance has the following attributes: global (g flag is set), ignoreCase (i flag is set) , the multiline (m flag is set), Source (return regular expression string), (start position when the next match) the lastIndex; instance has the following methods: ① a regular instance (string pattern) .exec; the method returns a successful match of the first string array, the array comprising two attributes: index and input, the position index indicates a successful match, input string flag regular expression, the first term is the complete array of matched string, no On the g flag is set to return only one match into a string, continue to call the g flag after setting the second method matching string is returned; ② regular instances .test (string to test); successful return match ture, otherwise false; RegExp constructor has the following properties: ①input property returns the original string; ②leftContext property returns the string before the match string; ③lastMatch property returns the entire string last regular expression matching; ④lastParen property returns last matched capturing group
  5. Function类型:函数是对象,函数名是指针,访问函数指针而不执行需要把函数名的括号去掉;①函数没有重载:②函数声明与函数表达式:函数声明会函数执行之前解析并可以使用,而函数表达式只有函数执行到它的代码才执行;③函数内部属性:arguments和this,argument对象是一个类数组,这个类数组包含所有的参数,同时还有一个callee属性,指向函数本身,this的指向在代码的执行过程中可能会指向不同的对象;④函数的caller属性则返回调用该函数的函数的引用,也可以使用arguments.callee.caller表示;⑤函数的属性和方法:length和prototype,length属性表示函数希望接受参数的个数,prototype属性拥有对象所有实例的方法,函数有两个方法:apply(参数1:在其中运行的函数作用域this,参数2:参数列表可以是arguments对象或者数组)和call(this,逐个列出参数),这两个方法都相当于扩充了对象的实例的作用域,比如对象.call(对象实例)即可将对象中的this指向该对象实例,ES5定义了一个新的方法对象.bind(对象实例),这个方法而可以创建一个函数的实例,this将会指向传给bind函数的值
  6. 基本包装类型:String/Number/Boolean,在创建字符串数值布尔值,后台都会创建相应类型的实例然后调用指定的方法,最后销毁该实例;String类型的操作方法:charAt(基于0的字符串位置)将会返回相应的字符,charCodeAt(基于0的字符串位置)返回相应的字符的字符编码,实例.concat(字符串)返回一个拼接的字符串,slice(字符串开始位置,字符串结束位置),substr(字符串开始位置,字符串结束位置),它们都返回字符串,substring(字符串开始位置,返回的字符串个数),如果参数为负值,只有substr的第二个参数为默认为0,其余参数均与字符串长度相加得到新的参数,字符串位置的方法:实例.indexOf(要搜索的字符串),实例.lastIndexOf(要搜索的字符串),它们都返回相应的字符串所在的位置,当然也可以设置第二个参数表示开始搜索的位置;trim()方法返回字符出的副本,并删除所有前缀和后缀的空格,字符串大小写转换方法:toUpperCase()、toLowerCase();字符串的模式匹配方法:字符串.match(正则表达式),这个方法相当于RegExp的exec方法;字符串.search(正则表达式)该方法返回字符串中第一个匹配项的索引;字符串替换方法:字符串.replace(字符串或者正则表达式,字符串中要替换的字符),如果第一个参数是字符串,那么只会替换第一个匹配的字符项,第二个参数也可以是函数,此时函数的第一个参数表示匹配项,第二个参数表示当前索引,第三个参数表示原始字符串;字符串的分隔方法:字符串.split(指定的分隔符/RegExp对象,指定分隔后的数组大小(可选参数))该方法将会把字符串按照字符串中的标识即分隔符分割成多个子字符串并存入数组中;字符串比较的方法:字符串.localeCompare(字符串),如果参数中的字符串与需要比较的字符串相等,则返回0,否则返回-1/1
  7. 单体内置对象:①Global对象:该对象拥有URI编码的方法:encodeURI()只替换空格,encodeURIComponent()替换所有非字母数字字符,解码的方法:decodeURI(),decodeURLComponent()②Math对象:Math.min()/Math.max()能够比较并返回一组数据中的最大值和最小值,如果想传入数组则为Math.min.apply(Math,数组);舍入方法:ceil()向上舍入,floor()向下舍入,round()四舍五入;Math.random()*可能值的总数+第一个可能的值,返回随机数

Guess you like

Origin www.cnblogs.com/Liqian-Front-End-Engineer/p/11221972.html
Recommended