-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Closed
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.
Description
Version
v20.5.1
Platform
ubuntu 20.04, Microsoft Windows NT 10.0.19045.0 x64
Subsystem
No response
What steps will reproduce the bug?
When performing the document example for event, the results are different.
Lines 102 to 111 in e0fb3f7
```mjs | |
import { EventEmitter } from 'node:events'; | |
class MyEmitter extends EventEmitter {} | |
const myEmitter = new MyEmitter(); | |
myEmitter.on('event', (a, b) => { | |
console.log(a, b, this); | |
// Prints: a b {} | |
}); | |
myEmitter.emit('event', 'a', 'b'); | |
``` |
Even if you print console.log(this);
in the part where the callback is called in another mjs example, it is the same.
Lines 484 to 537 in e0fb3f7
```mjs | |
import { createServer, request } from 'node:http'; | |
import { connect } from 'node:net'; | |
import { URL } from 'node:url'; | |
// Create an HTTP tunneling proxy | |
const proxy = createServer((req, res) => { | |
res.writeHead(200, { 'Content-Type': 'text/plain' }); | |
res.end('okay'); | |
}); | |
proxy.on('connect', (req, clientSocket, head) => { | |
// Connect to an origin server | |
const { port, hostname } = new URL(`http://${req.url}`); | |
const serverSocket = connect(port || 80, hostname, () => { | |
clientSocket.write('HTTP/1.1 200 Connection Established\r\n' + | |
'Proxy-agent: Node.js-Proxy\r\n' + | |
'\r\n'); | |
serverSocket.write(head); | |
serverSocket.pipe(clientSocket); | |
clientSocket.pipe(serverSocket); | |
}); | |
}); | |
// Now that proxy is running | |
proxy.listen(1337, '127.0.0.1', () => { | |
// Make a request to a tunneling proxy | |
const options = { | |
port: 1337, | |
host: '127.0.0.1', | |
method: 'CONNECT', | |
path: 'www.google.com:80', | |
}; | |
const req = request(options); | |
req.end(); | |
req.on('connect', (res, socket, head) => { | |
console.log('got connected!'); | |
// Make a request over an HTTP tunnel | |
socket.write('GET / HTTP/1.1\r\n' + | |
'Host: www.google.com:80\r\n' + | |
'Connection: close\r\n' + | |
'\r\n'); | |
socket.on('data', (chunk) => { | |
console.log(chunk.toString()); | |
}); | |
socket.on('end', () => { | |
proxy.close(); | |
}); | |
}); | |
}); | |
``` |
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
// Prints: a b {}
What do you see instead?
// Prints: a b undefined
Additional information
In cjs examples, this
is output as {}
, while in mjs examples, this
is output as undefined
. It is necessary to check whether the output as undefined
is a problem or normal, and if not, the document needs to be modified.
Metadata
Metadata
Assignees
Labels
docIssues and PRs related to the documentations.Issues and PRs related to the documentations.