Created
September 4, 2017 19:58
-
-
Save hvitorino/33bc1d8b669136498ed5dc786ec136fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.name = "Heisenberg"; | |
let obj = { | |
name: "i'm obj", | |
sayMyName: function() { | |
console.log(this.name); | |
}, | |
sayMyArrowName: () => console.log(this.name) | |
}; | |
obj.sayMyName(); | |
obj.sayMyArrowName(); | |
let anotherObj = { | |
name: "i'm another obj" | |
} | |
obj.sayMyName.bind(anotherObj)(); | |
obj.sayMyArrowName.bind(anotherObj)(); |
Achei um ótimo recurso do ES6, apesar dessa inconsistência. JavaScript tá ficando fofo. Ainda não sei muito sobre ES7 mas chego lá.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depois de fazer esses testes, percebi que o contexto de uma arrow function é imutável, portanto o bind não vai fazer efeito nenhum sobre isso.
Além disso, a arrow function veio para resolver o problema do contexto, e para tal, concordo com o comportamento que faz com que o bind não tenha nenhum efeito sobre seu contexto.