All Downloads are FREE. Search and download functionalities are using the official Maven repository.

testsrc.doctests.with.doctest Maven / Gradle / Ivy

Go to download

A distribution of rhino which releases snapshots from a submodule folder containing forked sources.

The newest version!
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

js> load('testsrc/doctests/util.js');

js> // when the variable is not in the with-object, it'll be set on the outer scope
js> (function() { with ({}) { var foo = 1; }; return foo; })()
1

js> // when the function is not in the with-object, it'll be set on the outer scope
js> (function() { with ({}) { function foo() { return 2; } }; return foo(); })()
2

js> // when the variable is in the with-object, it will be updated on the with-object
js> (function() { var obj = {foo:0}; with (obj) { var foo = 3; }; return obj.foo; })()
3

js> // functions declared inside with blocks are always bound to the closest enclosing function
js> (function() { function foo(){ return 0; }; with ({}) { function foo() { return 4; } }; return foo(); })()
4

js> // functions declared inside with blocks do not affect the properties of the with-obj
js> (function() { var obj = {foo:5}; with (obj) { function foo() { return 0; } }; return obj.foo; })()
5





© 2015 - 2024 Weber Informatics LLC | Privacy Policy