Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HenriqueSilverio/a125e599be2b730708ed772576c86acf to your computer and use it in GitHub Desktop.

Select an option

Save HenriqueSilverio/a125e599be2b730708ed772576c86acf to your computer and use it in GitHub Desktop.

Revisions

  1. HenriqueSilverio created this gist May 3, 2025.
    42 changes: 42 additions & 0 deletions messages-communicating-objects.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    (new Number()).toString()
    // '0'

    (new Boolean()).toString()
    // 'false'

    (new Array('Hello', 'World')).toString()
    // 'Hello','World'

    (new Date('2025-05-03T23:11:10.312Z')).toString()
    // 'Sat May 03 2025 20:11:10 GMT-0300 (Brasilia Standard Time)'

    (new Error('Boom!')).toString()
    // 'Error: Boom!'


    class Money {
    constructor(amount, currency = '$') {
    this.amount = amount
    this.currency = currency
    }

    toString() {
    return `${this.currency}${this.amount}`
    }
    }

    class PhoneNumber {
    constructor(aNANP) {
    this.phoneNumber = aNANP
    }

    toString() {
    return this.phoneNumber.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3')
    }
    }

    (new Money(5)).toString()
    // '$5'

    (new PhoneNumber('2607768461')).toString()
    // '(260) 776-8461'