Don't ask me how I know that...

Voila:
    
    
    # nim js -d:nodejs -d:release --hints:off
    
    type
      Obj {.exportc.} = object
        name: cstring
        surname: cstring
        fullname: proc(): cstring
        greet: proc()
    
    proc `&`(a,b: cstring): cstring {.importcpp: "(#) + (#)".}
    
    var o {.exportc.}: Obj
    
    o.name = "Hans"
    o.surname = "Raaf"
    o.fullname = proc (): cstring =
      var this {.importc,nodecl.}: Obj
      return this.name & " " & this.surname
    o.greet = proc () =
      var this {.importc,nodecl.}: Obj
      let txt: cstring = "Hello " & this.fullname()
      {.emit: "console.log(`txt`)\n".}
    
    o.greet()
    
    # or
    
    {.emit: "o.greet()\n".}
    

Reply via email to