public class JSFunction extends JSObject
JSObject.jsexport, JSObject.Property<T>
JSPropertyAttributeDontDelete, JSPropertyAttributeDontEnum, JSPropertyAttributeNone, JSPropertyAttributeReadOnly
Constructor and Description |
---|
JSFunction(org.liquidplayer.javascript.JNIJSObject objRef,
JSContext context)
Wraps an existing object as a JSFunction
|
JSFunction(JSContext ctx)
Creates a new function which basically does nothing.
|
JSFunction(JSContext ctx,
java.lang.reflect.Method method)
Creates a new function object which calls method 'method' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.reflect.Method method,
java.lang.Class<? extends JSObject> instanceClass)
Creates a new function object which calls method 'method' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.reflect.Method method,
java.lang.Class<? extends JSObject> instanceClass,
JSObject invokeObject)
Creates a new function object which calls method 'method' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.String methodName)
Creates a new function object which calls method 'methodName' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.String methodName,
java.lang.Class<? extends JSObject> instanceClass)
Creates a new function object which calls method 'methodName' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.String methodName,
java.lang.Class<? extends JSObject> instanceClass,
JSObject invokeObject)
Creates a new function object which calls method 'methodName' on this Java object.
|
JSFunction(JSContext ctx,
java.lang.String name,
java.lang.String[] parameterNames,
java.lang.String body,
java.lang.String sourceURL,
int startingLineNumber)
Creates a JavaScript function that takes parameters 'parameterNames' and executes the
JS code in 'body'.
|
JSFunction(JSContext ctx,
java.lang.String name,
java.lang.String body,
java.lang.String... parameterNames)
Creates a JavaScript function that takes parameters 'parameterNames' and executes the
JS code in 'body'.
|
Modifier and Type | Method and Description |
---|---|
JSValue |
apply(JSObject thiz,
java.lang.Object[] args)
Calls this JavaScript function, similar to 'Function.apply() in JavaScript
|
JSValue |
call()
Calls this JavaScript function with no args and 'this' as null
|
JSValue |
call(JSObject thiz,
java.lang.Object... args)
Calls this JavaScript function, similar to 'Function.call()' in JavaScript
|
JSObject |
newInstance(java.lang.Object... args)
Calls this JavaScript function as a constructor, i.e.
|
__nullFunc, deleteProperty, getThis, hashCode, hasProperty, isConstructor, isFunction, property, property, property, propertyAtIndex, propertyAtIndex, propertyNames, prototype, prototype
equals, getContext, isArray, isBoolean, isDate, isEqual, isFloat32Array, isFloat64Array, isInstanceOfConstructor, isInt16Array, isInt32Array, isInt8Array, isNull, isNumber, isObject, isStrictEqual, isString, isTypedArray, isUint16Array, isUint32Array, isUint8Array, isUint8ClampedArray, isUndefined, toBoolean, toFunction, toJSArray, toJSON, toNumber, toObject, toString, valueHash, valueRef
public JSFunction(JSContext ctx, @NonNull java.lang.String name, @NonNull java.lang.String[] parameterNames, @NonNull java.lang.String body, java.lang.String sourceURL, int startingLineNumber)
ctx
- The JSContext in which to create the functionname
- The name of the functionparameterNames
- A String array containing the names of the parametersbody
- The JavaScript code to execute in the functionsourceURL
- The URI of the source file, only used for reporting in stack trace (optional)startingLineNumber
- The beginning line number, only used for reporting in stack trace (optional)public JSFunction(JSContext ctx, @NonNull java.lang.String name, @NonNull java.lang.String body, java.lang.String... parameterNames)
ctx
- The JSContext in which to create the functionname
- The name of the functionparameterNames
- A String array containing the names of the parametersbody
- The JavaScript code to execute in the functionpublic JSFunction(JSContext ctx, java.lang.reflect.Method method, java.lang.Class<? extends JSObject> instanceClass, JSObject invokeObject)
var f = function(a) { ... };
Example:
public class FunctionObject extends JSObject {
void function(int x) {
getThis().property("varx",x);
}
}
public class MyFunc extends JSFunction {
MyFunc(JSContext ctx) {
super(ctx,
FunctionObject.class.getMethod("function",int.class), // will call method 'function'
JSObject.class // calling 'new' will create a JSObject
new FunctionObject(ctx) // function will be called on FunctionObject
);
}
}
ctx
- The JSContext to create the object inmethod
- The method to invokeinstanceClass
- The class to be created on 'new' callinvokeObject
- The object on which to invoke the methodpublic JSFunction(JSContext ctx, java.lang.reflect.Method method, java.lang.Class<? extends JSObject> instanceClass)
var f = function(a) { ... };
Example:
public class MyFunc extends JSFunction {
MyFunc(JSContext ctx) {
super(ctx,
MyFunc.class.getMethod("function",int.class), // will call method 'function'
JSObject.class // calling 'new' will create a JSObject
);
}
void function(int x) {
getThis().property("varx",x);
}
}
ctx
- The JSContext to create the object inmethod
- The method to invokeinstanceClass
- The class to be created on 'new' callpublic JSFunction(JSContext ctx, java.lang.reflect.Method method)
var f = function(a) { ... };
Example:
public class MyFunc extends JSFunction {
MyFunc(JSContext ctx) {
super(ctx,
MyFunc.class.getMethod("function",int.class), // will call method 'function'
JSObject.class // calling 'new' will create a JSObject
);
}
void function(int x) {
getThis().property("varx",x);
}
}
ctx
- The JSContext to create the object inmethod
- The method to invokepublic JSFunction(JSContext ctx)
var f = function() {};
Example:
JSFunction f = new JSFunction(context);
ctx
- The JSContext to create the object inpublic JSFunction(JSContext ctx, java.lang.String methodName, java.lang.Class<? extends JSObject> instanceClass, JSObject invokeObject)
var f = function(a) { ... };
Example:
public class FunctionObject extends JSObject {
void function(int x) {
getThis().property("varx",x);
}
}
public class MyFunc extends JSFunction {
MyFunc(JSContext ctx) {
super(ctx,
"function", // will call method 'function'
JSObject.class // calling 'new' will create a JSObject
new FunctionObject(ctx) // function will be called on FunctionObject
);
}
}
ctx
- The JSContext to create the object inmethodName
- The method to invoke (searches for first instance)instanceClass
- The class to be created on 'new' callinvokeObject
- The object on which to invoke the methodpublic JSFunction(JSContext ctx, java.lang.String methodName, java.lang.Class<? extends JSObject> instanceClass)
var f = function(a) { ... };
Example:
JSFunction f = new JSFunction(context,"function",JSObject.class) {
void function(int x) {
getThis().property("varx",x);
}
}
ctx
- The JSContext to create the object inmethodName
- The method to invoke (searches for first instance)instanceClass
- The class to be created on 'new' callpublic JSFunction(JSContext ctx, java.lang.String methodName)
var f = function(a) { ... };
Example:
JSFunction f = new JSFunction(context,"function") {
void function(int x) {
getThis().property("varx",x);
}
}
ctx
- The JSContext to create the object inmethodName
- The method to invoke (searches for first instance)public JSFunction(org.liquidplayer.javascript.JNIJSObject objRef, JSContext context)
objRef
- The JavaScriptCore object referencecontext
- The JSContext the objectpublic JSValue call(JSObject thiz, java.lang.Object... args)
thiz
- The 'this' object on which the function operates, null if not on a constructor objectargs
- The argument list to be passed to the functionpublic JSValue apply(JSObject thiz, java.lang.Object[] args)
thiz
- The 'this' object on which the function operates, null if not on a constructor objectargs
- An array of arguments to be passed to the functionpublic JSValue call()
public JSObject newInstance(java.lang.Object... args)
args
- The argument list to be passed to the function