testsrc.doctests.object.defineproperties.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
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> Object.defineProperties
function defineProperties() { [native code for Object.defineProperties, arity=2] }
js> expectTypeError(function() { Object.defineProperties() });
js> expectTypeError(function() { Object.defineProperties({}) });
js> [undefined, null, true, 1, 'hello'].forEach(function(value) {
> expectTypeError(function() { Object.defineProperties(value, {}) })
> })
js> Object.defineProperties({}, {p: {value:1}}).p
1
js> var obj = Object.defineProperties({}, {a: {value:1}, b: {value:2}});
js> [obj.a, obj.b].toSource();
[1, 2]
js> Object.defineProperties({}, {'wierd name': {value:1}})['wierd name']
1
js> Object.defineProperties({}, {}).toSource()
({})
js> var obj = {a:1};
js> var obj = Object.defineProperties(obj, {a:{value:2}, b:{value:3}});
js> [obj.a, obj.b].toSource()
[2, 3]
js> expectTypeError(function() { Object.defineProperties({}, {a: null}) })
js> expectTypeError(function() { Object.defineProperties({}, {a: 1}) })
js> expectTypeError(function() { Object.defineProperties({}, {a: {get: 1}}) })
js> var obj = {a:1}
js> expectTypeError(function() {
> obj = Object.defineProperties(obj, {b: {value:1}, c:1});
> });
js> obj.b
js>
js> Object.defineProperties({}, {'0.0': {value:1}, 0: {value:2}})['0']
2
© 2015 - 2025 Weber Informatics LLC | Privacy Policy