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: #8183
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: Robert Jefe Lindstaedt <robert.lindstaedt@gmail.com>
  • Loading branch information
shaikh-shahid authored and evanlucas committed Aug 24, 2016
1 parent b8f5a2b commit afbe4d8
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 afbe4d8

Please sign in to comment.