# 3.3.8 socket.on(eventName,callback)

* `eventName` (String)
* `callback` (Function)
* **Returns** `Socket`

为给定事件注册新的处理程序。

```javascript
socket.on('news',(data)=>{
    console.log(data)
})

// 多个参数

socket.on('new',(arg1,arg2,arg3,arg4)=>{
    // ...
})

// 使用回调

socket.on('news',(cb)=>{
    cb(0)
})
```

socket实际上继承了[Emitter](https://github.com/component/emitter)类的每个方法，比如`hasListeners`，`once`或`off`（删除一个事件监听器


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://socket.gitbook.io/docs/3-ke-hu-duan-apiclientapi/3.3-socket/socket_on_eventname_callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
