rhino1.7.6.testsrc.doctests.with.doctest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rhino Show documentation
Show all versions of rhino Show documentation
Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically
embedded into Java applications to provide scripting to end users.
// 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