Skip to content

Instantly share code, notes, and snippets.

@phsantiago
Created January 2, 2019 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phsantiago/18f5a8a40aff17374f03a367121ccb31 to your computer and use it in GitHub Desktop.
Save phsantiago/18f5a8a40aff17374f03a367121ccb31 to your computer and use it in GitHub Desktop.
class Gato {
constructor(nome) {
this.nome = nome;
}
falar(paraPessoas) {
paraPessoas.forEach(function(pessoa){
console.log(`${this.nome} para ${pessoa}: Meow!`);
})
}
};
const Pablo = new Gato('Pablo');
Pablo.falar(['Pedro', 'Elizabeth']);
// Uncaught TypeError: Cannot read property 'nome' of undefined
// at <anonymous>:8:29
// at Array.forEach (<anonymous>)
// at Gato.falar (<anonymous>:7:19)
// at <anonymous>:14:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment