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.
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.
2023-10-29
Ecco un piccolo trucchetto per fare in modo che la funzione di callback associata ad un listener venga eseguita solo una volta e che il listener venga automaticamente rimosso.
1// <button id="one-shot-hero-button">Batman! Help me!</button>
2
3const fakeHeroEl = document.getElementById('one-shot-hero-button');
4fakeHeroEl.addEventListener('click', function(event) {
5 console.log('Call me one time and no more!');
6}, {once: true});
7
8fakeHeroEl.click() // Call me one time and no more!
9fakeHeroEl.click() //
2023-10-27
Animazioni e transizioni posso essere belle da vedere...ma non per tutti! Con poco effort possiamo rendere le animazioni più accessibili per rendere la navigazione del nostro sito piacevole anche a persone che soffrono di disturbi visivi. Come?
1.animation {
2 animation: amazing-animation 1s linear infinite both;
3 background-color: red;
4}
5
6/* Change animation to avoid vestibular motion triggers */
7@media (prefers-reduced-motion) {
8 .animation {
9 animation: accessible-animation 4s linear infinite both;
10 background-color: green;
11 }
12}
2021-10-04
1// JS Tip of the Day
2// How to set entire document editable
3
4document.designMode = 'on'; // use it with Developer Tools Console.
2021-08-02
1// JS Tip of the Day
2// Set the primitive value of an object - easy way
3
4class Hero {
5 constructor(hero = 'Batman') {
6 this.hero = hero;
7 }
8
9 valueOf() {
10 return `I'm ${this.hero}`;
11 }
12}
13
14console.log(new Hero()); // { hero: 'Batman' }
15console.log(`${new Hero()}!!!!`); // I'm Batman!
2021-07-29
1// JS Tip of the Day
2// Import and parse JSON with modules (Chrome 91+)
3
4/* heroes.json
5{
6 "heroes": [
7 { "name": "Batman", "weapon": "Batarang" },
8 { "name": "Superman", "weapon": "himself" }
9 ]
10}
11*/
12
13import heroes from './heroes.json' assert { type: "json" };
14console.log(heroes); // { heroes: Array(2) }
15// or
16const heroesModule = await import('../db.json', { assert: { type: 'json' } });
17console.log(heroesModule.default); // { heroes: Array(2) }
18
19
20/*
21 NB: The new import assertions feature allows module import statements
22 to include additional information.
23 For instance, if you use the assertions, it fails if responds with
24 a non-JSON MIME type.
25*/
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.