← Torna al blog

Dev Tips

Un trucchetto al giorno leva le complicazioni di torno! Piccole "scorciatoie" che possono facilitare la vita degli sviluppatori e far risparmiare tempo...e righe di codice.

90

How to use Contact Picker (FUGU Project)

2021-05-28

1// JS Tip of the Day
2// How to use Contact Picker (FUGU Project)
3
4const supported = ('contacts' in navigator && 'ContactsManager' in window);
5
6if (supported) {
7  const props = ['name', 'email', 'tel'];
8  
9  try {
10    const contacts = await navigator.contacts.select(props, { multiple: true });
11    handleResults(contacts);
12  } catch (e) {
13    // ...
14  }
15}
89

Remove falsy values from an Array

2021-05-27

1// JS Tip of the Day
2// Remove falsy values from an Array
3
4const arr = ['Batman', null, 42, false, undefined];
5arr.filter(Boolean); // ['Batman', 42]
88

Console placeholders

2021-05-27

1// JS Tip of the Day
2// Console placeholders
3
4const hero = { name: "Batman", weapon: "Batarang" };
5console.log('Hi %s! You are %i years old! Wooooooah!',  hero.name, 81);
6// Hi Batman! You are 81 years old! Wooooooah!
7
8console.info('Hi %s! Your object is %o',  hero.name, hero);
9// Hi Batman! Your object is {name: "Batman", weapon: "Batarang"}
87

Asyncronous Script Loading with Async and Defer

2021-05-25

1// JS Tip of the Day
2// Asyncronous Script Loading with Async and Defer
3
4
5<!-- executed before window.load / no order matter / HTML Parsing Paused -->
6<script async src=”myAsyncScript.js” onload=”myAsyncInit()></script>
7
8<!-- executed before DOMContentLoaded / order matter / Execution after HTML Parsing --> 
9<script defer src=”myDeferScript.js” onload=”myDeferInit()></script>
86

Simple Code Generator

2021-05-24

1// JS Tip of the Day
2// Simple Code Generator
3
4const code = Math.random().toString(36).substring(2);
5console.log(code); // e.g. f3bkxjlpcbp

Contattaci.

Hai in mente un progetto e vorresti realizzarlo?
Sei interessato a migliorare le competenze del tuo team in ambito di programmazione e sviluppo?
Oppure vuoi semplicemente prendere prendere un caffè con noi e vedere la nostra collezione di Action Figure, allora scrivici tramite questo form.

Se, invece, vuoi far parte del team, guarda le nostre offerte di lavoro.

Questo sito è protetto da reCAPTCHA e si applicano le Norme sulla privacy e i Termini di servizio di Google.