← 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.
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.
2021-02-26
1// JS Tip of the Day
2// Batman 1966 Theme (old but gold tip)!!!!
3
4console.log(`${Array(16).join(Number('1966 Theme'))} Batman!`);
5
6// Today is my birthday ... I hope you enjoy this weird but awesome tip! :D
2021-02-25
1// JS Tip of the Day
2// Shuffle Array Items
3
4const heroes = ['Batman', 'Superman', 'Wonder Woman'];
5
6const sortRandom = (arr) => arr.sort(() => Math.random() - 0.5);
7
8console.log(sortRandom(heroes));
2021-02-24
1// JS Tip of the Day
2// Quick ways to clone objects
3
4const hero = { name: 'Batman', weapon: 'Batarang' };
5
6// Spread Operator - Shallow Clone - ES2015/ES6
7const newHeroSpread = { ...hero };
8
9// Rest Operator - Shallow Clone - ES2015/ES6
10const { ...newHeroRest } = hero;
11
12// Object.assign - Shallow Clone - ES2015/ES6
13const newHeroAssign = Object.assign({}, hero);
14
15// JSON methods - Deep Clone (without function or Symbol properties)
16const newHeroJSON = JSON.parse(JSON.stringify(hero));
17
18// Native deep cloning (only Node.js)
19const v8 = require('v8');
20const deepClone = obj => {
21 return v8.deserialize(v8.serialize(obj));
22};
23
24const newHeroV8 = deepClone(hero);
25
26// or Deep Clone with Underscore, Lodash, Ramda, your Custom Function, ...
2021-02-23
1// JS Tip of the Day
2// Get the last item(s) in an array
3
4const heroes = ['Batman', 'Superman', 'Wonder Woman'];
5
6console.log(heroes.slice(-1)); // ['Wonder Woman']
7console.log(heroes.slice(-2)); // ['Superman','Wonder Woman']
2021-02-22
1// JS Tip of the Day
2// Checking if a key exists in an object
3
4const hero = { name: 'Batman', weapon: 'Batarang' };
5
6// hasOwnProperty
7console.log(hero.hasOwnProperty("vehicle")); // false
8// in operator
9console.log('name' in hero); // true
10// Get elements (brackets style)
11console.log(hero["vehicle"]); // undefined
12// Get elements (object style)
13console.log(hero.vehicle); // undefined
14
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.