Skip to content

Instantly share code, notes, and snippets.

View codemilli's full-sized avatar
😇
Hooked on React Hooks

codemilli codemilli

😇
Hooked on React Hooks
View GitHub Profile
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}`);
}
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
hello () {
console.log(`My name is ${this.firstName} ${this.lastName}`);
}
}
let obj1 = {
cb: function () {
let that = this;
let fun = function () {
console.log('this => ', this); // undefined
console.log('that => ', that); // { cb: [Function] }
};
fun();
}
let a = (a) => {
return a + 1;
};
let b = b => b + 1;
let c = () => ({hacker: 'moon'});
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}
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
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"}}
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();
const a = { prop: 'haha' };
console.log('prop => ', a.prop); // haha
a.prop = 'hihi';
console.log('prop => ', a.prop); // hihi
const a = 'haha'; // a = 'haha'
a = 'hihi'; // Assignment to constant variable