JavaScript
32.1K subscribers
1.06K photos
10 videos
33 files
737 links
A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes!

Let's chat: @nairihar
Download Telegram
😆
Please open Telegram to view this post
VIEW IN TELEGRAM
1🤣565🔥4🤔1
CHALLENGE

const source = {
value: 1,
subscribers: new Set(),
subscribe(fn) {
this.subscribers.add(fn);
return () => this.subscribers.delete(fn);
},
next(newValue) {
this.value = newValue;
this.subscribers.forEach(fn => fn(this.value));
}
};

const mapped = {
value: undefined,
source,
transform: x => x * 2,
init() {
this.source.subscribe(val => {
this.value = this.transform(val);
console.log(`Mapped: ${this.value}`);
});
}
};

mapped.init();
source.next(3);
source.next(5);
console.log(`Final: ${mapped.value}`);
source.next(2);
5
😮 Apple App Store frontend source code archive

How is this possible?

Because Apple forgot to disable sourcemaps in production on the App Store website 🙃
Please open Telegram to view this post
VIEW IN TELEGRAM
🤣128🔥3
CHALLENGE

const target = { name: 'John', age: 30 };
const handler = {
get(obj, prop) {
if (prop in obj) {
return `[${obj[prop]}]`;
}
return `missing: ${prop}`;
},
set(obj, prop, value) {
obj[prop] = value.toUpperCase();
return true;
}
};
const proxy = new Proxy(target, handler);
proxy.city = 'paris';
console.log(proxy.name);
console.log(proxy.city);
console.log(proxy.country);
4👍3🔥1
And there is another fork 😆
Please open Telegram to view this post
VIEW IN TELEGRAM
🤣9
CHALLENGE

const user = {
profile: {
settings: {
theme: 'dark'
}
}
};

const getTheme = (obj) => obj?.profile?.settings?.theme ?? 'light';
const getLanguage = (obj) => obj?.profile?.settings?.language ?? 'en';
const getNotifications = (obj) => obj?.profile?.notifications?.enabled ?? true;

console.log(getTheme(user));
console.log(getLanguage(user));
console.log(getNotifications(user));
console.log(getTheme(null));
1
CHALLENGE

const moduleMap = new Map();

async function loadModule(name) {
if (moduleMap.has(name)) {
return moduleMap.get(name);
}

const module = await Promise.resolve({
default: () => `Module ${name} loaded`,
version: '1.0.0'
});

moduleMap.set(name, module);
return module;
}

loadModule('auth').then(m => console.log(m.default()));
loadModule('auth').then(m => console.log(m.version));
loadModule('db').then(m => console.log(m.default()));
2👍1