Golang perk series : prefix-less functions #2.1 (2023ed.)

projektorius96

LG

Posted on August 12, 2022

Golang perk series : prefix-less functions #2.1 (2023ed.)

"GLOBAL" FUNCTIONS :

Omit the global prefix : window in JS, fmt in Go :

In JavaScript :

function main(){
   /* window. */print()
}
main()
Enter fullscreen mode Exit fullscreen mode

In Golang :

package main 

import (
  . "fmt"
)

func main(){
  /* fmt. */Println("123")
} 
Enter fullscreen mode Exit fullscreen mode

"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)
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
projektorius96
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.

Related