Golang perk series : prefix-less functions #2.1 (2023ed.)
LG
Posted on August 12, 2022
"GLOBAL" FUNCTIONS :
Omit the global prefix : window in JS, fmt
in Go :
In JavaScript :
function main(){
/* window. */print()
}
main()
In Golang :
package main
import (
. "fmt"
)
func main(){
/* fmt. */Println("123")
}
"Struct" is a rough objects in Go :
package main
import (
. "fmt"
)
type myObject struct{
firstName string
lastName string
}
func definePerson(firstName string, lastName string) any {
// similar to feature in ES6 : if parameters matches object (~struct) fields,..
// ...then we can avoid repeating them, just by defining them as values i.e.:
return myObject{
/* firstName: */firstName,
/* lastName: */lastName,
};
}
func main() {
res := definePerson("John", "Doe")
Println(res)
}
💖 💪 🙅 🚩
LG
Posted on August 12, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.