-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathnewFunction.js
54 lines (37 loc) · 1.24 KB
/
newFunction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
function write(v) { WScript.Echo(v + ""); }
// No arguments
var f = new Function();
write(f());
// Just the body
var f0 = new Function("return 10;");
write(f0());
var f1 = new Function("a", "return a;");
write(f1());
write(f1(100));
var f2 = new Function("a", "b", "return a+b;");
write(f2());
write(f2(10));
write(f2(10,20));
// All of f3? should be the same
var f31 = new Function("a", "b", "c", "return a+b+c;");
var f32 = new Function("a,b,c", "return a+b+c;");
var f33 = new Function("a,b", "c", "return a+b+c;");
write(f31());
write(f32());
write(f33());
write(f31(10,20,30));
write(f32(10,20,30));
write(f33(10,20,30));
// Check the name binding
var x = "global";
function fNameBinding() {
var x = "local";
var y = new Function("return x;");
write(y());
return x + " " + y();
}
write(fNameBinding());