Các phương thức trong Golang | Cấp độ trung cấp

Tác giả: Sreekanth
Ngày xuất bản: 2023-06-19T00:00:00
Length: 17:30

Tóm tắt nội dung

Mô tả

Explains how methods work in Go, things like method normalization, method value evaluation, gotchas and best practices. It also explains the reasons for choosing between pointer and value receiver.

0:00 Basics of Methods

1:21 Value vs Pointer receivers

2:55 Methods on nil values

3:44 Pass by copy

5:54 Pass by copy with slices

7:58 Method normalization

9:25 Method value evaluation

11:01 Gotcha - calling method in range loop

12:26 New types won't get methods of base type

12:53 Choosing between pointer and value receiver

Intermediate level Golang playlist: https://youtu.be/RVTfPy_NELc?list=PLSozy2hb5kKPpIJnpZ2sSMfjVjP0tyJYG

Dave Cheney's blog posts:

https://dave.cheney.net/2016/03/19/should-methods-be-declared-on-t-or-t

https://dave.cheney.net/2015/11/18/wednesday-pop-quiz-spot-the-race

Code review wiki: https://github.com/golang/go/wiki/CodeReviewComments#receiver-type

Dịch Vào Lúc: 2025-07-06T11:10:43Z

Yêu cầu dịch (Một bản dịch khoảng 5 phút)

Phiên bản 3 (ổn định)

Tối ưu hóa cho một người nói. Phù hợp cho video chia sẻ kiến thức hoặc giảng dạy.

Video Đề Xuất