DEV Community

Discussion on: Add vibration to your web applications

Collapse
 
sunflower profile image
sunflowerseed

it is possible to condense it to

window && window.navigator && window.navigator.vibrate && window.navigator.vibrate([200, 100, 200]);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
aminnairi profile image
Amin

Yes absolutely. From now I guess it's a matter of development practice. But this would work as well (I haven't test it though but it seems working to me).

Collapse
 
alangdm profile image
Alan Dávalos

Or with optional chaining even better to

window?.navigator?.vibrate?.([200,100,200]);
Collapse
 
aminnairi profile image
Amin

Beware that this is still in experimental support! So if the browser does not support this syntax this will throw an error.

But I would of course use this syntax if I was using a transpirer for instance. Really shorten the syntax and looks nice!

Thread Thread
 
alangdm profile image
Alan Dávalos

Sure, then again the browsers that support vibrate and actually vibrate support it so for the most part it's harmless