This file contains hidden or 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
<div id="content"></div> | |
<button id="load">Vador says...</button> | |
<script> | |
const content = document.querySelector('#content'); | |
const click = function() { | |
content.innerHTML = 'Luke, ...'; | |
fetch('/api/users/luke') | |
.then(response => response.json()) |
This file contains hidden or 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
function Jedi() { | |
let jedi = ""; | |
this.luke = () => { | |
jedi = "Luke"; | |
return this; | |
} | |
this.imYourFather = () => `${jedi}, Je suis ton père`; | |
} |
This file contains hidden or 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
const luke = "luke"; | |
let jedi; | |
function foo(){ | |
const vador = "je suis ton père"; | |
function bar(){ | |
console.log(luke, vador); | |
} | |
This file contains hidden or 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
const jedi = "JavaScript"; | |
function foo(){ | |
console.log(jedi); // JavaScript | |
} | |
foo(); |
This file contains hidden or 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
class Foo { | |
constructor() { | |
this.counter = 0; | |
} | |
inc() { | |
this.counter += 1; | |
console.log(this); | |
}; | |
}; |
This file contains hidden or 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
function max() { | |
return (arguments.length === 0) ? 0 : Math.max.apply(Math, arguments); | |
} | |
max(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); //=> 9 | |
max(3, 8, 32, 2, 98); //=> 98 | |
max(42, 0); //=> 42 | |
max(); //=> 0 |
This file contains hidden or 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
function every(list, callback) { | |
for (let i = 0; i < list.length; i += 1) { | |
callback.call(list, i); | |
}; | |
} | |
every(['a', 42, false, {}], (index) => { | |
console.log('1', this); //=> ['a', 42, false, {}] | |
console.log('2', this[index]); //=> 'a', 42, false, {} | |
console.log('3', this[index + 1]); //=> 42, false, {}, undefined |
This file contains hidden or 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
function foo() { | |
console.log(this); //=> this === element | |
console.log(arguments); //=> a, b, c | |
} | |
var element = document.querySelector('#foo'); | |
element.addEventListener('click', (e) => { | |
console.log(this); //=> element | |
console.log(arguments); //=> e === Event |
This file contains hidden or 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
function foo() { | |
console.log(this); //=> this === element | |
console.log(arguments); //=> 'a', 'b', 'c' | |
} | |
var element = document.querySelector('#foo'); | |
element.addEventListener('click', (e) => { | |
console.log(this); //=> element | |
console.log(arguments); //=> e === Event | |
This file contains hidden or 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
function foo() { | |
console.log(this); //=> this === window | |
console.log(arguments); //=> 'a', 'b', 'c' | |
} | |
var element = document.querySelector('#foo'); | |
element.addEventListener('click', (e) => { | |
console.log(this); //=> element | |
console.log(arguments); //=> e === Event |