JavaScript
32K subscribers
1.04K photos
10 videos
33 files
717 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
CHALLENGE

console.log('1');

Promise.resolve().then(() => {
console.log('2');
Promise.resolve().then(() => console.log('3'));
});

Promise.resolve().then(() => {
console.log('4');
});

setTimeout(() => console.log('5'), 0);

console.log('6');
❀5πŸ‘4
🀟 A Year of Improving Node.js Compatibility in Cloudflare Workers

β€œWe’ve been busy,” says Cloudflare which recently announced it’s bringing Node.js HTTP server support to its Workers function platform. This post goes deep into the technicalities, covering what areas of the standard library is supported, how the file system works (Workers doesn’t have a typical file system), how input/output streams work, and more. And you can use all of this now.

James M Snell (Cloudflare)
Please open Telegram to view this post
VIEW IN TELEGRAM
❀7πŸ”₯3πŸ‘1
CHALLENGE

function processData() {
try {
console.log('processing');
return 'success';
} catch (error) {
console.log('error caught');
return 'failed';
} finally {
console.log('cleanup');
}
}

const result = processData();
console.log('result:', result);
πŸ”₯1
Please open Telegram to view this post
VIEW IN TELEGRAM
🀣10❀3πŸ‘1
CHALLENGE

class EventEmitter {
constructor() { this.events = {}; }
on(event, fn) { (this.events[event] ||= []).push(fn); }
emit(event, data) { this.events[event]?.forEach(fn => fn(data)); }
}

class Logger {
log(msg) { console.log(`LOG: ${msg}`); }
}

class Counter {
constructor() { this.count = 0; }
increment() { this.count++; console.log(this.count); }
}

function withLogging(target) {
const logger = new Logger();
return new Proxy(target, {
get(obj, prop) {
if (typeof obj[prop] === 'function') {
return function(...args) {
logger.log(`calling ${prop}`);
return obj[prop].apply(obj, args);
};
}
return obj[prop];
}
});
}

const emitter = withLogging(new EventEmitter());
const counter = new Counter();
emitter.on('tick', () => counter.increment());
emitter.emit('tick');
emitter.emit('tick');
πŸ€”3