org.mozilla.javascript

## 类 FunctionObject

- java.lang.Object
- - org.mozilla.javascript.ScriptableObject
  - - org.mozilla.javascript.IdScriptableObject
    - - org.mozilla.javascript.BaseFunction
      - - org.mozilla.javascript.FunctionObject

- 所有已实现的接口:
    java.io.Serializable, org.mozilla.javascript.Callable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Function, org.mozilla.javascript.IdFunctionCall, org.mozilla.javascript.Scriptable

      public class FunctionObject
      extends org.mozilla.javascript.BaseFunction

  另请参阅:
    序列化表格

- - ### 字段概要

    字段
    限定符和类型 | 字段和说明
    --- | ---
    `static int` | `JAVA_BOOLEAN_TYPE`
    `static int` | `JAVA_DOUBLE_TYPE`
    `static int` | `JAVA_INT_TYPE`
    `static int` | `JAVA_OBJECT_TYPE`
    `static int` | `JAVA_SCRIPTABLE_TYPE`
    `static int` | `JAVA_STRING_TYPE`
    `static int` | `JAVA_UNSUPPORTED_TYPE`

    - ### 从类继承的字段 org.mozilla.javascript.ScriptableObject

      `CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST`

    - ### 从接口继承的字段 org.mozilla.javascript.Scriptable

      `NOT_FOUND`

  - ### 构造器概要

    构造器
    构造器和说明
    `FunctionObject(java.lang.String name, java.lang.reflect.Member methodOrConstructor, org.mozilla.javascript.Scriptable scope)` Create a JavaScript function object from a Java method.

  - ### 方法概要

    所有方法 静态方法 实例方法 具体方法 已过时的方法
    限定符和类型 | 方法和说明
    --- | ---
    `void` | `addAsConstructor(org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable prototype)` Define this function as a JavaScript constructor.
    `java.lang.Object` | `call(Context cx, org.mozilla.javascript.Scriptable scope, org.mozilla.javascript.Scriptable thisObj, java.lang.Object[] args)` Performs conversions on argument types if needed and invokes the underlying Java method or constructor.
    `static java.lang.Object` | `convertArg(Context cx, org.mozilla.javascript.Scriptable scope, java.lang.Object arg, java.lang.Class<?> desired)` 已过时。 Use `getTypeTag(Class)` and `convertArg(Context, Scriptable, Object, int)` for type conversion.
    `static java.lang.Object` | `convertArg(Context cx, org.mozilla.javascript.Scriptable scope, java.lang.Object arg, int typeTag)`
    `org.mozilla.javascript.Scriptable` | `createObject(Context cx, org.mozilla.javascript.Scriptable scope)` Return new `Scriptable` instance using the default constructor for the class of the underlying Java method.
    `int` | `getArity()` Return the value defined by the method used to construct the object (number of parameters of the method, or 1 if the method is a "varargs" form).
    `java.lang.String` | `getFunctionName()`
    `int` | `getLength()` Return the same value as `getArity()`.
    `java.lang.reflect.Member` | `getMethodOrConstructor()` Get Java method or constructor this function represent.
    `static int` | `getTypeTag(java.lang.Class<?> type)`

    - ### 从类继承的方法 org.mozilla.javascript.BaseFunction

      `construct, execIdCall, getClassName, getTypeOf, hasInstance, setImmunePrototypeProperty`

    - ### 从类继承的方法 org.mozilla.javascript.IdScriptableObject

      `activatePrototypeMap, defineOwnProperty, delete, exportAsJSClass, get, getAttributes, has, hasPrototypeMap, initPrototypeConstructor, initPrototypeMethod, initPrototypeValue, put, setAttributes`

    - ### 从类继承的方法 org.mozilla.javascript.ScriptableObject

      `associateValue, avoidObjectDetection, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, deleteProperty, deleteProperty, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, has, hasProperty, hasProperty, isConst, isEmpty, isExtensible, isSealed, preventExtensions, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size`

    - ### 从类继承的方法 java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### 从接口继承的方法 org.mozilla.javascript.Scriptable

      `delete, delete, get, get, getDefaultValue, getIds, getParentScope, getPrototype, has, has, put, put, setParentScope, setPrototype`

- - ### 字段详细资料

    - #### JAVA_UNSUPPORTED_TYPE

          public static final int JAVA_UNSUPPORTED_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_STRING_TYPE

          public static final int JAVA_STRING_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_INT_TYPE

          public static final int JAVA_INT_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_BOOLEAN_TYPE

          public static final int JAVA_BOOLEAN_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_DOUBLE_TYPE

          public static final int JAVA_DOUBLE_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_SCRIPTABLE_TYPE

          public static final int JAVA_SCRIPTABLE_TYPE

      另请参阅:
        常量字段值

    - #### JAVA_OBJECT_TYPE

          public static final int JAVA_OBJECT_TYPE

      另请参阅:
        常量字段值

  - ### 构造器详细资料

    - #### FunctionObject

          public FunctionObject(java.lang.String name,
                                java.lang.reflect.Member methodOrConstructor,
                                org.mozilla.javascript.Scriptable scope)

      Create a JavaScript function object from a Java method.

      The `member` argument must be either a java.lang.reflect.Method or a java.lang.reflect.Constructor and must match one of two forms.

      The first form is a member with zero or more parameters of the following types: Object, String, boolean, Scriptable, int, or double. The Long type is not supported because the double representation of a long (which is the EMCA-mandated storage type for Numbers) may lose precision. If the member is a Method, the return value must be void or one of the types allowed for parameters.

      The runtime will perform appropriate conversions based upon the type of the parameter. A parameter type of Object specifies that no conversions are to be done. A parameter of type String will use Context.toString to convert arguments. Similarly, parameters of type double, boolean, and Scriptable will cause Context.toNumber, Context.toBoolean, and Context.toObject, respectively, to be called.

      If the method is not static, the Java 'this' value will correspond to the JavaScript 'this' value. Any attempt to call the function with a 'this' value that is not of the right Java type will result in an error.

      The second form is the variable arguments (or "varargs") form. If the FunctionObject will be used as a constructor, the member must have the following parameters

                (Context cx, Object[] args, Function ctorObj,
                 boolean inNewExpr)

      and if it is a Method, be static and return an Object result.

      Otherwise, if the FunctionObject will not be used to define a constructor, the member must be a static Method with parameters

                (Context cx, Scriptable thisObj, Object[] args,
                 Function funObj)

      and an Object result.

      When the function varargs form is called as part of a function call, the `args` parameter contains the arguments, with `thisObj` set to the JavaScript 'this' value. `funObj` is the function object for the invoked function.

      When the constructor varargs form is called or invoked while evaluating a `new` expression, `args` contains the arguments, `ctorObj` refers to this FunctionObject, and `inNewExpr` is true if and only if a `new` expression caused the call. This supports defining a function that has different behavior when called as a constructor than when invoked as a normal function call. (For example, the Boolean constructor, when called as a function, will convert to boolean rather than creating a new object.)

      参数:
        `name` - the name of the function
        `methodOrConstructor` - a java.lang.reflect.Method or a java.lang.reflect.Constructor that defines the object
        `scope` - enclosing scope of function
      另请参阅:
        `Scriptable`

  - ### 方法详细资料

    - #### getTypeTag

          public static int getTypeTag(java.lang.Class<?> type)

      返回:
        One of `JAVA_*_TYPE` constants to indicate desired type or `JAVA_UNSUPPORTED_TYPE` if the convertion is not possible

    - #### convertArg

          public static java.lang.Object convertArg(Context cx,
                                                    org.mozilla.javascript.Scriptable scope,
                                                    java.lang.Object arg,
                                                    int typeTag)

    - #### getArity

          public int getArity()

      Return the value defined by the method used to construct the object (number of parameters of the method, or 1 if the method is a "varargs" form).
      覆盖:
        `getArity` 在类中 `org.mozilla.javascript.BaseFunction`

    - #### getLength

          public int getLength()

      Return the same value as `getArity()`.
      覆盖:
        `getLength` 在类中 `org.mozilla.javascript.BaseFunction`

    - #### getFunctionName

          public java.lang.String getFunctionName()

      覆盖:
        `getFunctionName` 在类中 `org.mozilla.javascript.BaseFunction`

    - #### getMethodOrConstructor

          public java.lang.reflect.Member getMethodOrConstructor()

      Get Java method or constructor this function represent.

    - #### addAsConstructor

          public void addAsConstructor(org.mozilla.javascript.Scriptable scope,
                                       org.mozilla.javascript.Scriptable prototype)

      Define this function as a JavaScript constructor.

      Sets up the "prototype" and "constructor" properties. Also calls setParent and setPrototype with appropriate values. Then adds the function object as a property of the given scope, using `prototype.getClassName()` as the name of the property.

      参数:
        `scope` - the scope in which to define the constructor (typically the global object)
        `prototype` - the prototype object
      另请参阅:
        `Scriptable.setParentScope(org.mozilla.javascript.Scriptable)`, `Scriptable.setPrototype(org.mozilla.javascript.Scriptable)`, `Scriptable.getClassName()`

    - #### convertArg

          @Deprecated
          public static java.lang.Object convertArg(Context cx,
                                                                 org.mozilla.javascript.Scriptable scope,
                                                                 java.lang.Object arg,
                                                                 java.lang.Class<?> desired)

      已过时。 Use `getTypeTag(Class)` and `convertArg(Context, Scriptable, Object, int)` for type conversion.

    - #### call

          public java.lang.Object call(Context cx,
                                       org.mozilla.javascript.Scriptable scope,
                                       org.mozilla.javascript.Scriptable thisObj,
                                       java.lang.Object[] args)

      Performs conversions on argument types if needed and invokes the underlying Java method or constructor.

      Implements Function.call.

      指定者:
        `call` 在接口中 `org.mozilla.javascript.Callable`
      指定者:
        `call` 在接口中 `org.mozilla.javascript.Function`
      覆盖:
        `call` 在类中 `org.mozilla.javascript.BaseFunction`
      另请参阅:
        `Function.call( Context, Scriptable, Scriptable, Object[])`

    - #### createObject

          public org.mozilla.javascript.Scriptable createObject(Context cx,
                                                                org.mozilla.javascript.Scriptable scope)

      Return new `Scriptable` instance using the default constructor for the class of the underlying Java method. Return null to indicate that the call method should be used to create new objects.
      覆盖:
        `createObject` 在类中 `org.mozilla.javascript.BaseFunction`