Skip to content

Commit

Permalink
doc: add es6 code example in util.md
Browse files Browse the repository at this point in the history
Added class/extends example to util.md

PR-URL: nodejs#8183
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Yorkie Liu <[email protected]>
Reviewed-By: Robert Jefe Lindstaedt <[email protected]>
  • Loading branch information
shaikh-shahid authored and jasnell committed Aug 21, 2016
1 parent ce8753a commit 9a91ffb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ stream.on('data', (data) => {
stream.write('It works!'); // Received data: "It works!"
```

ES6 example using `class` and `extends`

```js
const util = require('util');
const EventEmitter = require('events');

class MyStream extends EventEmitter {
constructor() {
super();
}
write(data) {
this.emit('data', data);
}
}

const stream = new MyStream();

stream.on('data', (data) => {
console.log(`Received data: "${data}"`);
});
stream.write('With ES6');

```

## util.inspect(object[, options])

* `object` {any} Any JavaScript primitive or Object.
Expand Down

0 comments on commit 9a91ffb

Please sign in to comment.