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

rhino1.7.6.testsrc.doctests.object.create.doctest Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 1.7.15
Show 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.create;
function create() { [native code for Object.create, arity=2] }

js> expectTypeError(function() { Object.create() });
js> [undefined, true, 1, 'hello'].forEach(function(value) { 
  >   expectTypeError(function() { Object.create(value) }) 
  > })
js> expectTypeError(function() { Object.create({}, null) }) 

js> var obj = Object.create({});
js> var obj = Object.create({}, {});
js> var obj = Object.create({}, undefined);

js> var orig = {}
js> var next = Object.create(orig);
js> Object.getPrototypeOf(next) === orig;
true

js> var obj = Object.create({}, {a: {value:1}, b: {value:2}});
js> [obj.a, obj.b].toSource();
[1, 2]

js> var orig = {a:1};
js> var obj = Object.create(orig, {a:{value:2}, b:{value:3}});
js> [obj.a, obj.b].toSource()
[2, 3]

js> expectTypeError(function() { Object.create({}, {b: {value:1}, c:1}) });

js> var obj = Object.create(null, {a: {value:1}})
js> Object.getPrototypeOf(obj) === null
true





© 2015 - 2024 Weber Informatics LLC | Privacy Policy