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
| var btn = document.getElementById('button'); | |
| btn.addEventListener('click', function () { | |
| console.log('Hello, Universe'); | |
| }); |
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 listen(element, eventName) { | |
| return new Observable(observer => { | |
| // Create an event handler which sends data to the sink | |
| let handler = event => observer.next(event); | |
| // Attach the event handler | |
| element.addEventListener(eventName, handler, true); | |
| // Return a function which will cancel the event stream | |
| return () => { |
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 Developer extends Person { | |
| constructor (firstName, lastName, role) { | |
| super(firstName, lastName); | |
| this.role = role; | |
| } | |
| hello () { | |
| console.log(`My name is ${this.firstName} ${this.lastName} and I am a ${this.role}`); | |
| } | |
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 Person { | |
| constructor(firstName, lastName) { | |
| this.firstName = firstName; | |
| this.lastName = lastName; | |
| } | |
| hello () { | |
| console.log(`My name is ${this.firstName} ${this.lastName}`); | |
| } | |
| } |
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
| let obj1 = { | |
| cb: function () { | |
| let that = this; | |
| let fun = function () { | |
| console.log('this => ', this); // undefined | |
| console.log('that => ', that); // { cb: [Function] } | |
| }; | |
| fun(); | |
| } |
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
| let a = (a) => { | |
| return a + 1; | |
| }; | |
| let b = b => b + 1; | |
| let c = () => ({hacker: 'moon'}); |
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
| let wm = new WeakMap(); | |
| let key = {a: 1}; | |
| wm.set(key, 1).set({b: 2}, 2); | |
| console.log(wm); // WeakMap {Object {a: 1} => 1, Object {b: 2} => 2} | |
| // after the garbage collector has run | |
| console.log(wm); // WeakMap {Object {a: 1} => 1} |
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
| let map = new Map(); | |
| let obj = {a: 'haha'}; | |
| map.set(obj, 'hihi').set(1, 1).set(1, 2); | |
| console.log('map has 1 => ', map.has(1)); // true | |
| console.log('value of 1 => ', map.get(1)); // 2 | |
| map.delete(1); | |
| console.log('map has 1 => ', map.has(1)); // false |
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
| let ws = new WeakSet(); | |
| let value = {a: 'hacker'}; | |
| ws.add(value).add({b: 'moon'}); | |
| console.log(ws); // WeakSet {Object {a: "hacker"}, Object {b: "moon"}} | |
| // after the garbage collector has run | |
| console.log(ws); // WeakSet {Object {a: "hacker"}} |
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
| var s = new Set(); | |
| s.add(1).add(2).add(1); | |
| console.log('Size of s => ', s.size); // 2 | |
| console.log('s has 2 => ', s.has(2)); // true | |
| s.delete(2); | |
| console.log('s has 2 => ', s.has(2)); // false | |
| s.clear(); |