# 函数与this

## 2.匿名函数

It doesn’t work because it is being parsed as a FunctionDeclaration, and the name identifier of function declarations is mandatory.
When you surround it with parentheses it is evaluated as a FunctionExpression, and function expressions can be named or not.

The Parentheses (formally called the Grouping Operator) can surround only expressions, and a function expression is evaluated.

See more:

the Comma operator can also handle only expressions.

## 3.this

### 3.函数调用(Invoking a JavaScript Function)

1.函数直接调用(Invoking a Function as a Function)
2.作为对象方法调用(Invoking a Function as a Method)
3.作为构造函数调用(Invoking a Function with a Function Constructor)
4.call() && apply()调用(Invoking a Function with a Function Method)

#### 4.call() && apply()调用

• 直接函数调用可以看做是fn.call(window, undefined)，自然this便指向了window
• 方法调用可以看做是say.call(obj)，同理，this便指向了obj
• 构造函数，其实是使用new方法构造出了一个新的对象obj，也可以看做是fn.call(obj)this便指向了obj

• 全部
• 标签
• 友链