documentation


Node.js

jsdoc

  1. /**
  2. * Creates a new Person.
  3. * @class
  4. * @example
  5. * const person = new Person('bob')
  6. */
  7. class Person {
  8. /**
  9. * Create a person.
  10. * @param {string} [name] - The person's name.
  11. */
  12. constructor(name) {
  13. this.name = name
  14. }
  15. /**
  16. * Get the person's name.
  17. * @return {string} The person's name
  18. * @example
  19. * person.getName()
  20. */
  21. getName() {
  22. return this.name
  23. }
  24. /**
  25. * Set the person's name.
  26. * @param {string} name - The person's name.
  27. * @example
  28. * person.setName('bob')
  29. */
  30. setName(name) {
  31. this.name = name
  32. }
  33. }

Go

godoc

person.go

  1. package person
  2. import "fmt"
  3. // Person is the structure of a person
  4. type Person struct {
  5. name string
  6. }
  7. // NewPerson creates a new person. Takes in a name argument.
  8. func NewPerson(name string) *Person {
  9. return &Person{
  10. name: name,
  11. }
  12. }
  13. // GetName returns the person's name
  14. func (p *Person) GetName() string {
  15. return p.name
  16. }
  17. // SetName sets the person's name
  18. func (p *Person) SetName(name string) string {
  19. return p.name
  20. }

person_test.go

  1. // Example of creating a new Person.
  2. func ExampleNewPerson() {
  3. person := NewPerson("bob")
  4. _ = person
  5. }
  6. // Example of getting person's name.
  7. func ExamplePerson_GetName() {
  8. person := NewPerson("bob")
  9. fmt.Println(person.GetName())
  10. // Output: bob
  11. }
  12. // Example of setting person's name.
  13. func ExamplePerson_SetName() {
  14. person := NewPerson("alice")
  15. person.SetName("bob")
  16. }

<!—