Object built-in object

ObjectScript

Script script compilation and execution object

Create method

1
var Script = new vm.Script('console.log(100)');

inheritance relationship

Constructor

Script

Script object constructor

1 2
new 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 2
Value 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 2
Value 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

1
Value 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.

1
String 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.

1
Value Script.toJSON(String key = "");

Call parameters:

  • key: String, not used

Return results:

  • Value, returns a value containing JSON serializable