Skip to content

Instantly share code, notes, and snippets.

@evaporei
Created May 21, 2019 14:57
Show Gist options
  • Save evaporei/9969c5a8af59f88bf670408e505b3a8f to your computer and use it in GitHub Desktop.
Save evaporei/9969c5a8af59f88bf670408e505b3a8f to your computer and use it in GitHub Desktop.
Aula JS

Aulas de JS

Tópicos a serem abordados

  • Tipos de variáveis, escopo e closures (var, let, const, escopos function e {})
  • Tipos e coerção (Boolean, null, undefined, Number, String, Object, Symbol e tabela de coerção)
  • this, prototypes e classes
  • Assincronia (event loop, setTimeout, setInterval, setImmediate, process.nextTick, Promise, function*, coroutines e async await)
@evaporei
Copy link
Author

evaporei commented Jun 6, 2019

function bla () {

}

const sum = x => y => x + y

bla()

class Veiculo {
  constructor(tipo) {
    this.velocidade = 0
  }
}

class Carro extends Veiculo {
  constructor() {
    super()
    this.rodas = 4
  }

  andar() {
    console.log('anda')
    this.velocidade++
  }
}

const camaro = new Carro('r√°pido')
const fusca = new Carro('lento')

console.log(camaro)
console.log(fusca)

camaro.andar()

@evaporei
Copy link
Author

evaporei commented Jul 4, 2019

@evaporei
Copy link
Author

evaporei commented Jul 4, 2019

@evaporei
Copy link
Author

evaporei commented Jul 4, 2019

Explicar:

  • new Promise
  • then
  • catch
  • Promise.resolve
  • Promise.reject
  • Promise.all

@evaporei
Copy link
Author

evaporei commented Jul 11, 2019

const fs = require('fs')

fs.readFile('request_tables.js', 'utf-8', (error, arquivo) => {
  if (error) {
    return
  }
  console.log('arquivo', arquivo)
})

function readFilePromise (fileName) {
  return new Promise((resolve, reject) => {
    fs.readFile(fileName, 'utf-8', (error, arquivo) => {
      return reject(new Error('deu ruim pra ler o arquivo'))
      if (error) {
        return reject(error)
      }

      return resolve(arquivo)
    })
  })
}

readFilePromise('request_tables.js')
  .catch((error) => {
    console.log('catch', error)
    return Promise.resolve(2)
  })
  .then(valor => console.log('valor', valor))


// db.algumaCoisa()// errado
//   .catch()
//   .then()

// resolve
// fulfill
// reject

const um = () => Promise.resolve(1)
const dois = () => Promise.resolve(2)

Promise.all([um(), dois()])
  .then(([one]) => console.log('valores', one))
  .catch(error => console.log('error', error))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment