Writing a SerialDevice Class
Playing with a new library in an interactive environment is a great way to learn. Still, you eventually have to come up with some proper JavaScript code that you can actually use in your project.
JavaScript supports object-oriented programming, so it seems logical to put all code related to accessing the serial port into its own class. This way, you can reuse it in other projects, and if you have to fix bugs or improve the code, you have to do it only in one place. In addition, chances are good that there will be a cross-browser solution for accessing the serial port soon.[160] When this happens, you can replace the innards of your class with the new standard API, and your applications will work on all browsers automatically. ...
Get Arduino: A Quick-Start Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.