1. Recursion
Inside the function calls itself, the default is an infinite loop.
2. anonymous function
No function function name () {}
(1) create a function
Function declarations function fn1(){ } |
Function expression var fn2 = function (parameter) {function body;} The variable name is the name of the function |
Comparing the difference between function declarations and function expressions
Create a function exists to enhance the function declarations can be created in any position;
Function expressions using variables created, but there is a variable lift, enhance the function does not exist, can only be created, and then call.
(2) calls from anonymous function
Objective: Create a function scope wrapped to prevent global pollution.
(Function (shape attended table) { // function body of variables and functions can not be accessed outside }) (Argument list); |
(3) callback function
The anonymous function passed as argument, meaning that parameter is passed anonymous function name
function fn(a){ // Call fn when the anonymous function assigned to the parameter a, a function name is a Code () // anonymous function executor passed in } fn( function(){ ... } ); |
3. Global Functions
parseInt()/parseFloat()/isNaN()
the encodeURI () to encode the characters in the URL
decodeURI () already encoded URL is decoded
isFinite () determines whether the value of a is finite
Is -> true not -false
2/0 -> Infinity (infinity) 0/2 -> 0
eval () expression performed string
eval('1+2') //3
4. Objects
Belonging to the reference type data
Object: is a set of attributes (Property) and a method (method) of
A computer: attribute color, size, brand, memory size ... methods are watching video, Internet, knocking the code ..
Car: attribute color, length, brand, space travel ... methods, hauling goods, butt ...
Everything Is an Object
(1) object of JS
Built-in objects: JS provided
Host object: divided according to different execution environments
自定义对象: 自己创建的对象
(2)创建自定义对象
对象字面量
内置构造函数
自定义构造函数
(3)对象字面量创建对象
使用大括号创建空对象
属性名和属性值之间用冒号隔开
多组属性之间用逗号隔开
属性名中的引号可加可不加,如果含有特殊字符必须加
(4)访问对象中的属性
对象.属性名
对象['属性名']
如果访问的属性名不存在,返回undefined
(5)内置构造函数创建对象
new Object() 创建一个空对象
需要单独为对象添加每一个属性
(6)遍历对象中的属性
访问对象中的每一个属性
for(var key in 对象){ key 代表对象中的每个属性名 对象[key] 通过属性名或者对应属性值 } |