← 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.

100

WTFJS (old but gold)

2021-06-13

1// JS Tip of the Day - This is my 100th tip!
2// WTFJS (old but gold) 
3
4//You have to watch it! :D
5window.location.assign('https://www.youtube.com/watch?v=et8xNAc2ic8'); 
6
7//You have to visit it! :D
8window.location.assign('https://github.com/denysdovhan/wtfjs'); 
99

Simple Interaction with HID (Experimental)

2021-06-12

1// JS Tip of the Day
2// Simple Interaction with HID (Experimental)
3
4try {
5	const devices = await navigator.hid.requestDevice({filters: []});
6    console.log(`Device: ${devices[0].productName}`);
7    devices[0].open();
8    devices[0].addEventListener('inputreport', e => console.log(e));
9}
10catch(e) {
11	console.log(`No Device: ${e}`);
12}
98

How to request and detect the USB Devices (Experimental)

2021-06-10

1// JS Tip of the Day
2// How to request and detect the USB Devices (Experimental)
3
4// Request a Device
5const filters = {filters: []}; // You could filter by vendorId/productId
6
7await navigator.usb.requestDevice(filters)
8.then(device => console.log(`Device: ${device.productName}`))
9.catch(e => console.log(`No Device: ${e}`));
10
11// Get all a paired attached devices
12await navigator.usb.getDevices()
13.then(devices => {
14  console.log(`Devices: ${devices.length}`);
15  devices.forEach(device => console.log(`Device: ${device.productName}`));
16});
17
18// NB: Yes...I used top level await! :D
97

Get selected text on a web page

2021-06-09

1// JS Tip of the Day
2// Get selected text on a web page
3
4const getSelectedText = () => window.getSelection().toString();
5console.log(getSelectedText()); // 'Selected Text!'
96

How to emulate an Enum (very simple mode)

2021-06-09

1// JS Tip of the Day
2// How to emulate an Enum (very simple mode)
3
4const heroEnum = Object.assign(
5  Object.create(null),
6  {
7    batman: 'Batman',
8    superman: 'Superman',
9    cyborg: 'Cyborg'
10  }
11);
12
13Object.freeze(heroEnum);
14
15console.log(heroEnum) 
16// { batman: 'Batman', superman: 'Superman', cyborg: 'Cyborg' } 

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.