Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update util.md for ES6 extends code example #8183

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class and extends are keywords in JavaScript, so suggest highlighting these two words :-)


```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code class js or es6 is missing?

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