Saturday, April 27, 2019

class-less JavaScript ?

an interesting elaboration why using classes in JavaScript is an anti-pattern in some cases

Towards class-less JavaScript · Markus Tacker · Software Crafter

Dependency Injection without classes - Fun Fun Function - YouTube

await fetch in Chrome dev tools console

Here is a simple way to get data from a web URL in Chrome dev tools console.
Since fetch() is an async function that returns a javascript promise, need to use await keyword, that is now supported by Chrome dev tools console.

await fetch('https://jsonplaceholder.typicode.com/posts').then(r => r.json())
and to make result data nicely formatted as a table:

await fetch('https://jsonplaceholder.typicode.com/posts').then(r => r.json()).then(console.table)

Chrome/Firefox console.table()

Console.table() - Web APIs | MDN

// an array of arrays

var people = [["John", "Smith"], ["Jane", "Doe"], ["Emily", "Jones"]]
console.table(people);
Table displaying array of arrays

Console API Reference  |  Tools for Web Developers  |  Google Developers

console.table([
  {
    first: 'RenĂ©',
    last: 'Magritte',
  },
  {
    first: 'Chaim',
    last: 'Soutine',
    birthday: '18930113',
  },
  {
    first: 'Henri',
    last: 'Matisse',
  }
])
The result of the console.table() example above.
Console Overview  |  Tools for Web Developers  |  Google Developers