"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)
}
Top comments (0)