Skip to content

Commit 693d06a

Browse files
committed
Auto-generated commit
1 parent 15e4c8c commit 693d06a

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Milan Raj <rajsite@users.noreply.github.com>
2020
Momtchil Momtchev <momtchil@momtchev.com>
2121
Ognjen Jevremović <ognjenjevremovic@users.noreply.github.com>
2222
Philipp Burckhardt <pburckhardt@outlook.com>
23+
Pranav <85227306+Pranavchiku@users.noreply.github.com>
2324
Ricky Reusser <rsreusser@gmail.com>
2425
Ryan Seal <splrk@users.noreply.github.com>
2526
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>

docs/types/index.d.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,63 @@
2222
/* tslint:disable:max-file-line-count */
2323

2424
import Function = require( './../../ctor' );
25+
import function2string = require( './../../to-string' );
2526

2627
/**
2728
* Interface describing the `function` namespace.
2829
*/
2930
interface Namespace {
3031
/**
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
3250
*/
3351
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;
3482
}
3583

3684
/**

0 commit comments

Comments
 (0)