> For the complete documentation index, see [llms.txt](https://socket.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://socket.gitbook.io/docs/3-ke-hu-duan-apiclientapi/3.3-socket/socket_on_eventname_callback.md).

# 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`（删除一个事件监听器
