Object built-in object

Object Worker

Independent thread work object

Inheritance

Constructor

Worker

Worker object constructor

1 2
new Worker(String path, Object opts = {});

Call parameters:

  • path : String, specifies the worker entry script, only accepts absolute paths
  • opts : Object, construction options, not yet supported

Static property

defaultMaxListeners

Integer, default global maximum number of listeners

1
static Integer Worker.defaultMaxListeners;

Member attribute

onload

Function, query and binding to accept load message events, equivalent to on("load", func);

1
Function Worker.onload;

onmessage

Function, query and binding to accept postMessage events, equivalent to on("message", func);

1
Function Worker.onmessage;

onerror

Function, query and binding accept error message events, equivalent to on("error", func);

1
Function Worker.onerror;

Member function

postMessage

Send a message to Master or Worker,

1
Worker.postMessage(Value data);

Call parameters:

  • data : Value, specify the content of the message sent

on

Bind an event handler to the object

1 2
Object Worker.on(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Bind an event handler to the object

1
Object Worker.on(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event handler

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

addListener

Bind an event handler to the object

1 2
Object Worker.addListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Bind an event handler to the object

1
Object Worker.addListener(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event handler

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

prependListener

Bind an event handler to the beginning of the object

1 2
Object Worker.prependListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Bind an event handler to the beginning of the object

1
Object Worker.prependListener(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event handler

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

once

Bind a one-time event handler to the object, one-time handler will only trigger once

1 2
Object Worker.once(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Bind a one-time event handler to the object, one-time handler will only trigger once

1
Object Worker.once(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event handler

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

prependOnceListener

Bind an event handler to the beginning of the object

1 2
Object Worker.prependOnceListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Bind an event handler to the beginning of the object

1
Object Worker.prependOnceListener(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name will be used as the event name, and the attribute value will be used as the event handler

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

off

Cancel the specified function from the object processing queue

1 2
Object Worker.off(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Cancel all functions in the object processing queue

1
Object Worker.off(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Cancel the specified function from the object processing queue

1
Object Worker.off(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the attribute value is used as the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

removeListener

Cancel the specified function from the object processing queue

1 2
Object Worker.removeListener(String ev, Function func);

Call parameters:

  • ev : String, specify the name of the event
  • func : Function, specify the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Cancel all functions in the object processing queue

1
Object Worker.removeListener(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

Cancel the specified function from the object processing queue

1
Object Worker.removeListener(Object map);

Call parameters:

  • map : Object, specifies the event mapping relationship, the object attribute name is used as the event name, and the attribute value is used as the event processing function

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

removeAllListeners

Cancel all listeners for all events from the object processing queue, and if specified events, remove all listeners for the specified events.

1
Object Worker.removeAllListeners(Array evs = []);

Call parameters:

  • evs : Array, specify the name of the event

Return result:

  • Object , returns the event object itself, which is convenient for chained calls

setMaxListeners

The default limit number of listeners, only for compatibility

1
Worker.setMaxListeners(Integer n);

Call parameters:

  • n : Integer, specify the number of events

getMaxListeners

Get the default number of listeners, only for compatibility

1
Integer Worker.getMaxListeners();

Return result:

  • Integer , returns the default limit number

listeners

Array of listeners for the specified event of the query object

1
Array Worker.listeners(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Array , returns an array of listeners for the specified event

listenerCount

The number of listeners for the specified event of the query object

1
Integer Worker.listenerCount(String ev);

Call parameters:

  • ev : String, specify the name of the event

Return result:

  • Integer , returns the number of listeners for the specified event

eventNames

Query listener event name

1
Array Worker.eventNames();

Return result:

  • Array , returns an array of event names

emit

Actively trigger an event

1 2
Boolean Worker.emit(String ev, ...args);

Call parameters:

  • ev : String, event name
  • args : ..., event parameters, will be passed to the event handler function

Return result:

  • Boolean , returns the event trigger state, returns true if there is a response event, otherwise returns false

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented according to its own characteristics

1
String Worker.toString();

Return result:

  • String , returns a string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

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

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable