8. Using Yocto-RangeFinder with JavaScript /
EcmaScript
EcmaScript is the official name of the standardized version of the web-oriented programming
language commonly referred to as
JavaScript
. This Yoctopuce library take advantages of advanced
features introduced in EcmaScript 2017. It has therefore been named
Library for JavaScript /
EcmaScript 2017
to differentiate it from the previous
Library for JavaScript
, now deprecated in favor
of this new version.
This library provides access to Yoctopuce devices for modern JavaScript engines. It can be used
within a browser as well as with Node.js. The library will automatically detect upon initialization
whether the runtime environment is a browser or a Node.js virtual machine, and use the most
appropriate system libraries accordingly.
Asynchronous communication with the devices is handled across the whole library using Promise
objects, leveraging the new EcmaScript 2017
async
/
await
non-blocking syntax for asynchronous
I/O (see below). This syntax is now available out-of-the-box in most Javascript engines. No
transpilation is needed: no Babel, no jspm, just plain Javascript. Here is your favorite engines
minimum version needed to run this code. All of them are officially released at the time we write this
document.
• Node.js v7.6 and later
• Firefox 52
• Opera 42 (incl. Android version)
• Chrome 55 (incl. Android version)
• Safari 10.1 (incl. iOS version)
• Android WebView 55
• Google V8 Javascript engine v5.5
If you need backward-compatibility with older releases, you can always run Babel to transpile your
code and the library to older standards, as described a few paragraphs below.
We don't suggest using
jspm 0.17
anymore since that tool is still in Beta after 18 month, and
having to use an extra tool to implement our library is pointless now that
async
/
await
are part of
the standard.
8.1. Blocking I/O versus Asynchronous I/O in JavaScript
JavaScript is single-threaded by design. That means, if a program is actively waiting for the result of
a network-based operation such as reading from a sensor, the whole program is blocked. In browser
environments, this can even completely freeze the user interface. For this reason, the use of blocking
www.yoctopuce.com
37
Содержание Yocto-RangeFinder
Страница 1: ...Yocto RangeFinder User s guide...
Страница 2: ......
Страница 18: ...12 www yoctopuce com...
Страница 26: ...20 www yoctopuce com...
Страница 42: ...36 www yoctopuce com...
Страница 70: ...gcc lyocto lm lpthread lusb 1 0 lstdc 10 Using Yocto RangeFinder with C 64 www yoctopuce com...
Страница 90: ...84 www yoctopuce com...
Страница 120: ...114 www yoctopuce com...
Страница 130: ...124 www yoctopuce com...
Страница 158: ...21 High level API Reference On failure throws an exception or returns a negative error code 152 www yoctopuce com...
Страница 484: ...478 www yoctopuce com...
Страница 488: ...482 www yoctopuce com...
Страница 490: ...23 Characteristics 484 www yoctopuce com...
Страница 491: ......
Страница 492: ......