Object built-in object

Object FSWatcher

file system watcher

When the call is fs.watch(target)successful , an object of this type is returned

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
var fs = require("fs"); var watcher = fs.watch((eventType, filename) => { if (filename) { console.log(filename); // Prints: <Buffer ...> } }); watcher.close(); // 带回调地调用 fs.watch('./tmp', { encoding: 'buffer' }, (eventType, filename) => { if (filename) { console.log(filename); // Prints: <Buffer ...> } });

inheritance relationship

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<class>EventEmitter|new EventEmitter()|EventEmitter|defaultMaxListeners|on();addListener();prependListener();once();prependOnceListener();off();removeListener();removeAllListeners();setMaxListeners();getMaxListeners();listeners();listenerCount();eventNames();emit()] [<this>FSWatcher|onchange;onclose;onerror|close()] [object] <:- [EventEmitter] [EventEmitter] <:- [FSWatcher] EventEmitter new EventEmitter() EventEmitter defaultMaxListeners on() addListener() prependListener() once() prependOnceListener() off() removeListener() removeAllListeners() setMaxListeners() getMaxListeners() listeners() listenerCount() eventNames() emit() FSWatcher onchange onclose onerror close() object toString() toJSON()

static properties

defaultMaxListeners

Integer, the default global maximum number of listeners

1
static Integer FSWatcher.defaultMaxListeners;

Member properties

onchange

Function, query and bind the "file change" event, equivalent to on("change", func);

1
Function FSWatcher.onchange;

onclose

Function, query and bind the "watcher close" event, equivalent to on("close", func);

1
Function FSWatcher.onclose;

onerror

Function, query and bind the "error occurred" event, equivalent to on("error", func);

1
Function FSWatcher.onerror;

member function

close

Close the Watcher and no longer receive the corresponding file change processing events

1
FSWatcher.close();

on

Bind an event handler to an object

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Bind an event handler to an object

1
Object FSWatcher.on(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

addListener

Bind an event handler to an object

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Bind an event handler to an object

1
Object FSWatcher.addListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

prependListener

Bind an event handler to the object start

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Bind an event handler to the object start

1
Object FSWatcher.prependListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

once

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

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

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

1
Object FSWatcher.once(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

prependOnceListener

Bind an event handler to the object start

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Bind an event handler to the object start

1
Object FSWatcher.prependOnceListener(Object map);

Call parameters:

  • map: Object, specify the event mapping relationship, the object property name will be used as the event name, and the property value will be used as the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

off

cancel the specified function from the object processing queue

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Cancel all functions in the object processing queue

1
Object FSWatcher.off(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return result:

  • Object, returns the event object itself for easy chaining

cancel the specified function from the object processing queue

1
Object FSWatcher.off(Object map);

Call parameters:

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

Return result:

  • Object, returns the event object itself for easy chaining

removeListener

cancel the specified function from the object processing queue

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

Call parameters:

  • ev: String, specifies the name of the event
  • func: Function, specifies the event handler function

Return result:

  • Object, returns the event object itself for easy chaining

Cancel all functions in the object processing queue

1
Object FSWatcher.removeListener(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return result:

  • Object, returns the event object itself for easy chaining

cancel the specified function from the object processing queue

1
Object FSWatcher.removeListener(Object map);

Call parameters:

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

Return result:

  • Object, returns the event object itself for easy chaining

removeAllListeners

Cancels all listeners for all events from the object's processing queue, or if an event is specified, removes all listeners for the specified event.

1
Object FSWatcher.removeAllListeners(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return result:

  • Object, returns the event object itself for easy chaining

Cancels all listeners for all events from the object's processing queue, or if an event is specified, removes all listeners for the specified event.

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

Call parameters:

  • evs: Array, specifying the name of the event

Return result:

  • Object, returns the event object itself for easy chaining

setMaxListeners

The default limit on the number of listeners, for compatibility only

1
FSWatcher.setMaxListeners(Integer n);

Call parameters:

  • n: Integer, specifies the number of events

getMaxListeners

Gets the number of default limits for listeners, for compatibility only

1
Integer FSWatcher.getMaxListeners();

Return result:

  • Integer, returns the default limit number

listeners

Query the array of listeners for the specified event of the object

1
Array FSWatcher.listeners(String ev);

Call parameters:

  • ev: String, specifies 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 FSWatcher.listenerCount(String ev);

Call parameters:

  • ev: String, specifies the name of the event

Return result:

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

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

1 2
Integer FSWatcher.listenerCount(Value o, String ev);

Call parameters:

  • o: Value, specifies the object of the query
  • ev: String, specifies the name of the event

Return result:

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

eventNames

Query listener event name

1
Array FSWatcher.eventNames();

Return result:

  • Array, returns an array of event names

emit

Actively trigger an event

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

Call parameters:

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

Return result:

  • Boolean, returns the event trigger status, 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 FSWatcher.toString();

Return result:

  • String, returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns the set of readable properties defined by the object

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

Call parameters:

  • key: String, unused

Return result:

  • Value, returns a value containing JSON serializable