Debian Codegraph @

rhino/testsrc/doctests/with.doctest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 js> load('testsrc/doctests/util.js');
6
7 js> // when the variable is not in the with-object, it'll be set on the outer scope
8 js> (function() { with ({}) { var foo = 1; }; return foo; })()
9 1
10
11 js> // when the function is not in the with-object, it'll be set on the outer scope
12 js> (function() { with ({}) { function foo() { return 2; } }; return foo(); })()
13 2
14
15 js> // when the variable is in the with-object, it will be updated on the with-object
16 js> (function() { var obj = {foo:0}; with (obj) { var foo = 3; }; return obj.foo; })()
17 3
18
19 js> // functions declared inside with blocks are always bound to the closest enclosing function
20 js> (function() { function foo(){ return 0; }; with ({}) { function foo() { return 4; } }; return foo(); })()
21 4
22
23 js> // functions declared inside with blocks do not affect the properties of the with-obj
24 js> (function() { var obj = {foo:5}; with (obj) { function foo() { return 0; } }; return obj.foo; })()
25 5
26