ObjectScript
Script script compilation and execution object
Create method
1var Script = new vm.Script('console.log(100)');
inheritance relationship
Constructor
Script
Script object constructor
1
2new Script(String code,
Object opts = {});
Call parameters:
- code: String, specifies the script code to be compiled and run
- opts: Object, specify compilation and running options
member function
runInContext
Runs within the given contextualizedObjectvm.ScriptObject contains compiled code and returns the result
1
2Value Script.runInContext(Object contextifiedObject,
Object opts = {});
Call parameters:
- contextifiedObject: Object, specifies the runtime context object
- opts: Object, specify run options
Return results:
- Value, return the running result
runInNewContext
Run within the context created using the given contextObjectvm.ScriptObject contains compiled code and returns the result
1
2Value Script.runInNewContext(Object contextObject = {},
Object opts = {});
Call parameters:
- contextObject: Object, specifies the object to be contextualized
- opts: Object, specify run options
Return results:
- Value, return the running result
runInThisContext
Run within the current contextvm.ScriptObject contains compiled code and returns the result
1Value Script.runInThisContext(Object opts = {});
Call parameters:
- opts: Object, specify run options
Return results:
- Value, return the running result
toString
Returns the string representation of the object. Generally, "[Native Object]" is returned. The object can be re-implemented according to its own characteristics.
1String Script.toString();
Return results:
- String, returns the string representation of the object
toJSON
Returns a JSON format representation of the object, generally returning a collection of readable properties defined by the object.
1Value Script.toJSON(String key = "");
Call parameters:
- key: String, not used
Return results:
- Value, returns a value containing JSON serializable