|
22 | 22 | /* tslint:disable:max-file-line-count */ |
23 | 23 |
|
24 | 24 | import Function = require( './../../ctor' ); |
| 25 | +import function2string = require( './../../to-string' ); |
25 | 26 |
|
26 | 27 | /** |
27 | 28 | * Interface describing the `function` namespace. |
28 | 29 | */ |
29 | 30 | interface Namespace { |
30 | 31 | /** |
31 | | - * TODO |
| 32 | + * Returns a Function object. |
| 33 | + * |
| 34 | + * ## Notes |
| 35 | + * |
| 36 | + * - Argument names must be strings corresponding to valid JavaScript parameters (i.e., a plain identifier, or, in environments supporting such parameters, a rest parameter or destructured parameter, optionally with a default). |
| 37 | + * - Creating `Function` objects with the `Function` constructor is less efficient than declaring a function via a function expression or a function statement. |
| 38 | + * - The `Function` constructor can be invoked without the `new` operator (using `new` and not using `new` both return a new `Function` object). |
| 39 | + * - The `Function` constructor creates functions which execute in the **global scope**. Hence, created functions **cannot** access variables local to the scope in which functions were created. |
| 40 | + * |
| 41 | + * @param argNames - parameter names |
| 42 | + * @param body - function body |
| 43 | + * @returns function |
| 44 | + * |
| 45 | + * @example |
| 46 | + * var add = new ns.Function( 'x', 'y', 'return x + y' ); |
| 47 | + * |
| 48 | + * var v = add( 1, 2 ); |
| 49 | + * // returns 3 |
32 | 50 | */ |
33 | 51 | Function: typeof Function; |
| 52 | + |
| 53 | + /** |
| 54 | + * Returns a string representing the source code of a provided function. |
| 55 | + * |
| 56 | + * ## Notes |
| 57 | + * |
| 58 | + * - If called on built-in functions, functions created by `Function.prototype.bind()`, or other non-JavaScript functions, the function returns a "native" function string similar to the following: |
| 59 | + * |
| 60 | + * ```text |
| 61 | + * "function foo() { [native code] }" |
| 62 | + * ``` |
| 63 | + * |
| 64 | + * For intrinsic object methods and functions, `foo` is the initial name of the function. |
| 65 | + * |
| 66 | + * - If called on a function created by the `Function` constructor, the function returns the source code of a synthesized function declaration having the name "anonymous" and using the provided parameters and function body. |
| 67 | + * |
| 68 | + * - Starting in ES2018, the ECMAScript specification requires that the returned string contain the exact same source code as it was declared, including any whitespace and/or comments. If the host is unable to access the source code, the specification requires that the returned string be the native function string. |
| 69 | + * |
| 70 | + * @param fcn - input function |
| 71 | + * @returns string representing function source code |
| 72 | + * |
| 73 | + * @example |
| 74 | + * function add( x, y ) { |
| 75 | + * return x + y; |
| 76 | + * } |
| 77 | + * |
| 78 | + * var str = ns.function2string( add ); |
| 79 | + * // e.g., returns 'function add( x, y ) {\n return x + y;\n}' |
| 80 | + */ |
| 81 | + function2string: typeof function2string; |
34 | 82 | } |
35 | 83 |
|
36 | 84 | /** |
|
0 commit comments