Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const obj = {
- x: 5,
- func: function() { console.log(this.x); }, //wyświetli 5
- arrowfunc: () => { console.log(this.x) } //wyświetli undefined
- }
- const array = [1, 2]; //jakaś tablica, żebym mógł pętlę forEach na niej wykonać
- const object = {
- x: 5,
- func: function() { //tutaj musi być zwykła funkcja, aby skorzystać w środku z this.
- array.forEach( () => {
- console.log(this.x); //wyświetli 5 5, a jeśli zamienilibyśmy tę arrow function (w środku forEacha) na zwykłą to byłoby undefined
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement