Java Reference
In-Depth Information
// Create a Sequence object
var deptId = new Sequence();
print("deptId sequence...");
printf("Current Value = %d, next Value = %d", deptId.curValue(),
deptId.nextValue());
printf("Current Value = %d, next Value = %d", deptId.curValue(),
deptId.nextValue());
printf("Current Value = %d, next Value = %d", deptId.curValue(),
deptId.nextValue());
empId sequence...
Current Value = 0, next Value = 1
Current Value = 1, next Value = 2
Current Value = 2, next Value = 3
deptId sequence...
Current Value = 0, next Value = 1
Current Value = 1, next Value = 2
Current Value = 2, next Value = 3
Object Inheritance
Unlike Java, Nashorn does not have classes. Nashorn works with objects only. It supports
prototype-based object inheritance. Apart from the collection of properties, every
object in Nashorn has a prototype that is an object or the null value. You can access the
reference of the prototype of an object using the __proto__ property. Notice that there
are two underscores before and after the word proto in the property name __proto__ .
This property is deprecated and you can use the following two functions to get and set the
prototype of an object:
Object.getPrototypeOf(object)
Object.setPrototypeOf(object, newPrototype)
If a property in an object is accessed, first its own properties are searched. If the
property is found, it is returned. If the property is not found, the prototype of the object
is search. If the property is not found, the prototype of the prototype of the object is
searched, and so on. The search continues until the property is found in the prototype
chain or the entire prototype chain is searched. This search is the same as in class-based
inheritance in Java, where properties are searched up the class inheritance chain until the
java.lang.Object class is searched.
in Java, the class inheritance always extends up to the java.lang.Object class.
in nashorn, Object.prototype is the default prototype of an object. however, you can set
the prototype to any object, including the null value.
Tip
 
 
Search WWH ::




Custom Search