03.10.2012 Views

TypeScript Language Specification

TypeScript Language Specification

TypeScript Language Specification

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The JavaScript code generated for a super property access is specified in section 8.5.2.<br />

4.9 Function Expressions<br />

Function expressions are extended from JavaScript to optionally include parameter and return type<br />

annotations, and a new compact form, called arrow function expressions, is introduced.<br />

FunctionExpression: ( Modified )<br />

function Identifieropt CallSignature { FunctionBody }<br />

AssignmentExpression: ( Modified )<br />

…<br />

ArrowFunctionExpression<br />

ArrowFunctionExpression:<br />

ArrowFormalParameters => Block<br />

ArrowFormalParameters => AssignmentExpression<br />

ArrowFormalParameters:<br />

CallSignature<br />

Identifier<br />

The terms standard function expression and arrow function expression are used to refer to the<br />

FunctionExpression and ArrowFunctionExpression forms respectively. When referring to either, the generic<br />

term function expression is used.<br />

The type of a function expression is an object type containing a single call signature with parameter and<br />

return types inferred from the function expression’s signature and body.<br />

The descriptions of function declarations provided in section 6.1 apply to function expressions as well,<br />

except that function expressions do not support overloading.<br />

Function expressions with no parameter or return type annotations (but possibly with optional parameters<br />

and default parameter values) are contextually typed in certain circumstances, as described in section<br />

4.18. When a function expression is contextually typed by a function type T, the function expression is<br />

processed as if it had explicitly specified parameter and return type annotations as they exist in T.<br />

Parameters are matched by position and need not have matching names. If the function expression has<br />

fewer parameters than T, the additional parameters in T are ignored. If the function expression has more<br />

parameters than T, the additional parameters are all considered to have type Any.<br />

4.9.1 Standard Function Expressions<br />

Standard function expressions are function expressions written with the function keyword. The type of<br />

this in a standard function expression is the Any type.<br />

34

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!