JSObject (Nashorn API )
Keywords: jdk.nashorn.api.scripting.JSObject interface
Date: 2016-12-09

compact1, compact2, compact3
jdk.nashorn.api.scripting

## Interface JSObject

- All Known Implementing Classes:
    AbstractJSObject, ScriptObjectMirror

      @Exported
      public interface JSObject

  This interface can be implemented by an arbitrary Java class. Nashorn will treat objects of such classes just like nashorn script objects. Usual nashorn operations like obj[i], obj.foo, obj.func(), delete obj.foo will be delegated to appropriate method call of this interface.
  Since:
    1.8u40

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `call(Object thiz, Object... args)` Call this object as a JavaScript function.
    `Object` | `eval(String s)` Evaluate a JavaScript expression.
    `String` | `getClassName()` ECMA [[Class]] property
    `Object` | `getMember(String name)` Retrieves a named member of this JavaScript object.
    `Object` | `getSlot(int index)` Retrieves an indexed member of this JavaScript object.
    `boolean` | `hasMember(String name)` Does this object have a named member?
    `boolean` | `hasSlot(int slot)` Does this object have a indexed property?
    `boolean` | `isArray()` Is this an array object?
    `boolean` | `isFunction()` Is this a function object?
    `boolean` | `isInstance(Object instance)` Checking whether the given object is an instance of 'this' object.
    `boolean` | `isInstanceOf(Object clazz)` Checking whether this object is an instance of the given 'clazz' object.
    `boolean` | `isStrictFunction()` Is this a 'use strict' function object?
    `Set<String>` | `keySet()` Returns the set of all property names of this object.
    `Object` | `newObject(Object... args)` Call this 'constructor' JavaScript function to create a new object.
    `void` | `removeMember(String name)` Remove a named member from this JavaScript object
    `void` | `setMember(String name, Object value)` Set a named member in this JavaScript object
    `void` | `setSlot(int index, Object value)` Set an indexed member in this JavaScript object
    `double` | `toNumber()` Deprecated. use `AbstractJSObject.getDefaultValue(JSObject, Class)` with `Number` hint instead.
    `Collection<Object>` | `values()` Returns the set of all property values of this object.

- - ### Method Detail

    - #### call

          Object call(Object thiz,
                      Object... args)

      Call this object as a JavaScript function. This is equivalent to 'func.apply(thiz, args)' in JavaScript.
      Parameters:
        `thiz` - 'this' object to be passed to the function. This may be null.
        `args` - arguments to method
      Returns:
        result of call

    - #### newObject

          Object newObject(Object... args)

      Call this 'constructor' JavaScript function to create a new object. This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
      Parameters:
        `args` - arguments to method
      Returns:
        result of constructor call

    - #### eval

          Object eval(String s)

      Evaluate a JavaScript expression.
      Parameters:
        `s` - JavaScript expression to evaluate
      Returns:
        evaluation result

    - #### getMember

          Object getMember(String name)

      Retrieves a named member of this JavaScript object.
      Parameters:
        `name` - of member
      Returns:
        member
      Throws:
        `NullPointerException` - if name is null

    - #### getSlot

          Object getSlot(int index)

      Retrieves an indexed member of this JavaScript object.
      Parameters:
        `index` - index slot to retrieve
      Returns:
        member

    - #### hasMember

          boolean hasMember(String name)

      Does this object have a named member?
      Parameters:
        `name` - name of member
      Returns:
        true if this object has a member of the given name

    - #### hasSlot

          boolean hasSlot(int slot)

      Does this object have a indexed property?
      Parameters:
        `slot` - index to check
      Returns:
        true if this object has a slot

    - #### removeMember

          void removeMember(String name)

      Remove a named member from this JavaScript object
      Parameters:
        `name` - name of the member
      Throws:
        `NullPointerException` - if name is null

    - #### setMember

          void setMember(String name,
                         Object value)

      Set a named member in this JavaScript object
      Parameters:
        `name` - name of the member
        `value` - value of the member
      Throws:
        `NullPointerException` - if name is null

    - #### setSlot

          void setSlot(int index,
                       Object value)

      Set an indexed member in this JavaScript object
      Parameters:
        `index` - index of the member slot
        `value` - value of the member

    - #### keySet

          Set<String> keySet()

      Returns the set of all property names of this object.
      Returns:
        set of property names

    - #### values

          Collection<Object> values()

      Returns the set of all property values of this object.
      Returns:
        set of property values.

    - #### isInstance

          boolean isInstance(Object instance)

      Checking whether the given object is an instance of 'this' object.
      Parameters:
        `instance` - instance to check
      Returns:
        true if the given 'instance' is an instance of this 'function' object

    - #### isInstanceOf

          boolean isInstanceOf(Object clazz)

      Checking whether this object is an instance of the given 'clazz' object.
      Parameters:
        `clazz` - clazz to check
      Returns:
        true if this object is an instance of the given 'clazz'

    - #### getClassName

          String getClassName()

      ECMA [[Class]] property
      Returns:
        ECMA [[Class]] property value of this object

    - #### isFunction

          boolean isFunction()

      Is this a function object?
      Returns:
        if this mirror wraps a ECMAScript function instance

    - #### isStrictFunction

          boolean isStrictFunction()

      Is this a 'use strict' function object?
      Returns:
        true if this mirror represents a ECMAScript 'use strict' function

    - #### isArray

          boolean isArray()

      Is this an array object?
      Returns:
        if this mirror wraps a ECMAScript array object

    - #### toNumber

          @Deprecated
          double toNumber()

      Deprecated. use `AbstractJSObject.getDefaultValue(JSObject, Class)` with `Number` hint instead.
      Returns this object's numeric value.
      Returns:
        this object's numeric value.

Copyright © 2014, 2016, Oracle and/or its affiliates. All rights reserved.