[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-ep16-methods-interfaces-go-vs-javascript-all--*":3,"academy-blog-translations-locxsrgkk2e04x2":79},{"data":4,"page":78,"perPage":78,"totalItems":78,"totalPages":78},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":72,"keywords":73,"locale":49,"published_at":74,"scheduled_at":13,"school_blog":70,"short_description":75,"slug":76,"status":68,"title":6,"updated":77,"updated_by":13,"views":71},"JS2GO EP.16 Methods and Interfaces in Go vs JavaScript","sclblg987654321","school_blog_translations","\u003Cp>Methods and Interfaces are fundamental concepts in object-oriented programming and data structure design. Understanding how to create and use Methods and Interfaces allows you to write flexible, readable code and manage functions within structs or objects efficiently.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>This article compares how Methods and Interfaces work in Go and JavaScript\u002FTypeScript, with code examples, pros and cons, and usage recommendations.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Methods in Go\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In Go, Methods are functions attached to structs. You can use value receivers or pointer receivers to handle struct values.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Example of Methods\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\ntype Person struct {\n    Name string\n    Age  int\n}\n\n\u002F\u002F Value receiver\nfunc (p Person) Greet() {\n    fmt.Printf(\"Hello, my name is %s and I am %d years old\\n\", p.Name, p.Age)\n}\n\n\u002F\u002F Pointer receiver\nfunc (p *Person) HaveBirthday() {\n    p.Age += 1\n}\n\nfunc main() {\n    person := Person{Name: \"Alice\", Age: 25}\n    person.Greet()        \u002F\u002F Hello, my name is Alice and I am 25 years old\n    person.HaveBirthday()\n    person.Greet()        \u002F\u002F Hello, my name is Alice and I am 26 years old\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Pros\u003C\u002Fp>\u003Cul>\u003Cli>✨ Type-safe and clearly bound to structs\u003C\u002Fli>\u003Cli>✨ Pointer receivers allow modifying struct values\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Cons\u003C\u002Fp>\u003Cul>\u003Cli>⚠️ Structs must be declared before defining methods\u003C\u002Fli>\u003Cli>⚠️ No class-based inheritance\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Interfaces in Go\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Interfaces define the behavior of structs. Any struct implementing the required methods can be used wherever the interface is expected.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Example of Interfaces\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">package main\n\nimport \"fmt\"\n\ntype Greeter interface {\n    Greet()\n}\n\ntype Person struct {\n    Name string\n}\n\nfunc (p Person) Greet() {\n    fmt.Println(\"Hello, my name is\", p.Name)\n}\n\ntype Robot struct {\n    ID int\n}\n\nfunc (r Robot) Greet() {\n    fmt.Println(\"Beep boop! I am robot\", r.ID)\n}\n\nfunc SayHello(g Greeter) {\n    g.Greet()\n}\n\nfunc main() {\n    alice := Person{Name: \"Alice\"}\n    r2d2 := Robot{ID: 101}\n    \n    SayHello(alice)  \u002F\u002F Hello, my name is Alice\n    SayHello(r2d2)   \u002F\u002F Beep boop! I am robot 101\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Pros\u003C\u002Fp>\u003Cul>\u003Cli>✨ Decouples code and increases flexibility\u003C\u002Fli>\u003Cli>✨ Any struct implementing the interface can be used immediately\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Cons\u003C\u002Fp>\u003Cul>\u003Cli>⚠️ No enforcement of interface implementation\u003C\u002Fli>\u003Cli>⚠️ Can be confusing for beginners\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Methods and Objects in JavaScript\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In JavaScript, Methods are functions inside objects or classes.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Example: Methods in Objects\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">const person = {\n    name: \"Alice\",\n    age: 25,\n    greet() {\n        console.log(`Hello, my name is ${this.name} and I am ${this.age} years old`);\n    },\n    haveBirthday() {\n        this.age += 1;\n    }\n};\n\nperson.greet();       \u002F\u002F Hello, my name is Alice and I am 25 years old\nperson.haveBirthday();\nperson.greet();       \u002F\u002F Hello, my name is Alice and I am 26 years old\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch3>Example: Methods in Classes\u003C\u002Fh3>\u003Cpre>\u003Ccode class=\"language-javascript\">class Person {\n    constructor(name, age) {\n        this.name = name;\n        this.age = age;\n    }\n\n    greet() {\n        console.log(`Hello, my name is ${this.name} and I am ${this.age} years old`);\n    }\n\n    haveBirthday() {\n        this.age += 1;\n    }\n}\n\nconst alice = new Person(\"Alice\", 25);\nalice.greet();\nalice.haveBirthday();\nalice.greet();\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Pros\u003C\u002Fp>\u003Cul>\u003Cli>✨ Flexible and easy to use\u003C\u002Fli>\u003Cli>✨ Supports class-based and prototype-based OOP\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Cons\u003C\u002Fp>\u003Cul>\u003Cli>⚠️ Not type-safe\u003C\u002Fli>\u003Cli>⚠️ No built-in interface (requires TypeScript or design patterns)\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Interface Pattern in TypeScript\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In JavaScript, interfaces can be implemented using TypeScript:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-typescript\">interface Greeter {\n    greet(): void;\n}\n\nclass Person implements Greeter {\n    constructor(public name: string) {}\n    greet() {\n        console.log(`Hello, my name is ${this.name}`);\n    }\n}\n\nclass Robot implements Greeter {\n    constructor(public id: number) {}\n    greet() {\n        console.log(`Beep boop! I am robot ${this.id}`);\n    }\n}\n\nfunction sayHello(g: Greeter) {\n    g.greet();\n}\n\nconst alice = new Person(\"Alice\");\nconst r2d2 = new Robot(101);\n\nsayHello(alice);  \u002F\u002F Hello, my name is Alice\nsayHello(r2d2);   \u002F\u002F Beep boop! I am robot 101\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Comparison: Methods and Interfaces\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Feature\u003C\u002Fth>\u003Cth>Go\u003C\u002Fth>\u003Cth>JavaScript\u002FTypeScript\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Method Binding\u003C\u002Ftd>\u003Ctd>Bound to struct or pointer\u003C\u002Ftd>\u003Ctd>Bound to object or class\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Interface\u003C\u002Ftd>\u003Ctd>Built-in, decoupled behavior\u003C\u002Ftd>\u003Ctd>No built-in, use pattern\u002FTypeScript\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Type Safety\u003C\u002Ftd>\u003Ctd>High\u003C\u002Ftd>\u003Ctd>Low\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Inheritance\u003C\u002Ftd>\u003Ctd>No class-based inheritance\u003C\u002Ftd>\u003Ctd>Supports class-based inheritance\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Use Case\u003C\u002Ftd>\u003Ctd>Large systems, strict typing\u003C\u002Ftd>\u003Ctd>Web apps, flexible OOP\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Summary and Recommendations\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cul>\u003Cli>Go: Methods and Interfaces are ideal for large systems requiring type safety and behavior flexibility\u003C\u002Fli>\u003Cli>JavaScript\u002FTypeScript: Methods in objects or classes are suitable for web applications and highly flexible code\u003C\u002Fli>\u003Cli>Choose based on project type and needs for function and behavior management\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>Next Episode\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>In EP.17 of the JS2GO series, we will explore debugging in Go and JavaScript to make inspecting and fixing code errors easier and more effective.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp data-start=\"498\" data-end=\"834\">\u003Cstrong>Read more\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FGolang\">\u003Cstrong>Golang The Series\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FJS2GO\">\u003Cstrong>JS2GO\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fen\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\">\u003Cstrong>10 Eps That Will Make You a Pro Tailwind CSS Overnight\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevschool\u002F\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdevacademy.com\u002Fen\">\u003Cstrong>https:\u002F\u002Fwww.superdevacademy.com\u002Fen\u003C\u002Fstrong>\u003C\u002Fa>\u003Cstrong>&nbsp;\u003C\u002Fstrong>\u003C\u002Fp>","32_11zon_mh28i7expr.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002F1y0z1pdii39u5te\u002F32_11zon_mh28i7expr.webp","2026-03-04 08:46:42.241Z","",{"keywords":15,"locale":43,"school_blog":53},[16,23,28,33,38],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:45:30.765Z","nayuhpre9emd5xw","JS2GO","2026-04-10 16:12:59.160Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:46:41.057Z","0rsso9b0r2shb8t","Interfaces JavaScript","2026-04-10 16:13:17.412Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:46:41.436Z","gepo3qdsuz9cepe","Methods JavaScript","2026-04-10 16:13:17.577Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:46:41.635Z","wy7xha10l98zlz0","Interfaces Go","2026-04-10 16:13:17.641Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:46:41.857Z","2fc0mg5t0958mgt","Methods Go","2026-04-10 16:13:17.734Z",{"code":44,"collectionId":45,"collectionName":46,"created":47,"flag":48,"id":49,"is_default":50,"label":51,"updated":52},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":54,"collectionId":55,"collectionName":56,"expand":57,"id":70,"views":71},"hsa1afr8fcnd6qb","pbc_2105096300","school_blogs",{"category":58},{"blogIds":59,"collectionId":60,"collectionName":61,"created":62,"created_by":13,"id":54,"image":63,"image_alt":13,"image_path":64,"label":65,"name":21,"priority":66,"publish_at":67,"scheduled_at":13,"status":68,"updated":69,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:24:37.986Z","js2_go_2_11zon_y6paxmuz32.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fhsa1afr8fcnd6qb\u002Fjs2_go_2_11zon_y6paxmuz32.webp",{"en":21,"th":21},10,"2025-08-11 03:41:08.820Z","published","2026-04-25 02:32:14.339Z","locxsrgkk2e04x2",209,"1y0z1pdii39u5te",[20,25,30,35,40],"2025-09-01 10:59:00.471Z","Learn how to create and use Methods and Interfaces in Go and JavaScript with code examples, pros and cons, and practical usage recommendations.","ep16-methods-interfaces-go-vs-javascript","2026-04-25 02:48:07.132Z",1,{"en":76}]