-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathdeferredGetterSetter.js
44 lines (33 loc) · 1.4 KB
/
deferredGetterSetter.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
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
// /forcedeferparse test to make sure we can handle getters and setters at global scope,
// at function scope, and with nested functions.
var x = {
_y : 'x.y',
get y() { WScript.Echo('getting x.y'); return this._y; },
set y(val) { WScript.Echo('setting x.y'); this._y = val; }
};
WScript.Echo(x.y);
x.y = 'new x.y';
function f() {
var x = {
_y : 'local x.y',
get y() { WScript.Echo('getting local x.y'); return this._y; },
set y(val) { WScript.Echo('setting local x.y'); this._y = val; }
};
WScript.Echo(x.y);
x.y = 'new local x.y';
var nested_x = {
_y : 'nested x.y',
get y() { function fget(o) { WScript.Echo('getting nested x.y'); return o._y; } return fget(this); },
set y(val) { function fset(o, val) { WScript.Echo('setting nested x.y'); o._y = val; } fset(this, val); }
};
WScript.Echo(nested_x.y);
nested_x.y = 'new nested x.y';
WScript.Echo(nested_x.y);
WScript.Echo(x.y);
}
f();
WScript.Echo(x.y);