JavaScript 12

[라즈베리파이 크로스컴파일] 5. electron serialport 예제

거의 하루 종일 이것만 붙잡고 늘어졌다. 나의 고생이 누군가에게 해결책이 되길 바라며 포스팅을 남긴다. 뭔가 종말의 멘트 같잖아..? Electron 공식 문서에서는 Web API를 이용해서 SerialPort 모듈에 접근한다고 했는데, 따라 해 보니 너무 복잡하고 아두이노 한정 예제라 그런지 되지도 않았다. 그래서 Node.js의 SerialPort 라이브러리로 진행했다. https://serialport.io/docs/ About SerialPort | Node SerialPort Quick Answers to Important Questions serialport.io (참고로 윈도우 버전이다) 아~~~주 친절하게 install 할 수 있는 방법이 설명되어 있지만 절대 사용하지 않겠다...... 왜..

JS 함수 기본편!

출처. https://www.youtube.com/watch?v=PuG2VW18O1E&t=5s 어떤 함수를 어려워하는 구독자 때문에 만드셨다고 한다. 마음씨가 정말 따뜻하시다. 나도 배워야겠다. // Don't give up // 함수 선언 function doSomething(add) { console.log(add); //함수를 이용해서 안에서 사용 가능 const result = add(2, 3); console.log(result); } function add(a, b) { const sum = a + b; return sum; } // 함수 호출 doSomething(add); //함수를 전달함. 함수 자체를 전달해버림 function add() {} // const result = add(1,..

[라즈베리파이 크로스컴파일] 3. electron keyboard shortcuts 예제

출처. https://www.electronjs.org/docs/latest/tutorial/keyboard-shortcuts Keyboard Shortcuts | Electron This feature allows you to configure local and global keyboard shortcuts for your Electron application. www.electronjs.org 프로그램을 사용할 때 단축키를 지정해서 사용할 때가 있다. (Ctrl + S = 저장) 같이! QT5 하면서 keyPressEvent였나 키가 눌렸을 때 입력을 인지하는 API가 있었는데 Electron에서도 있다니 연습해봐야겠다. Local Short Cut 등록 후 Console창에서 출력하기! (Local..

JS async,await 입문!

출처. https://www.youtube.com/watch?v=aoQSOZfz3vQ 드디어 입문의 마지막이다. 동기와 비동기. 멀티스레딩이 아닌 곳에서 유용하게 쓰이는 만큼 어렵다. callback -> promise -> async, await으로 이어지는 전개가 좋았다. 'use strict'; const { reject } = require("async"); // async & await // clear style of using promise :) // 1. async // function fetchUser에 들어와서 10초 동안 처리를 기다리고 그 다음 일을 수행하게 된다. function fetchUser() { // do network request in 10 secs... return '..

JS Promise 입문!

출처. https://www.youtube.com/watch?v=JB_yU6Oe2eE&t=1053s JS꽃 동기와 비동기라니 C언어의 꽃 포인터가 생각나는 건 나뿐인가...? 어쨌든 어렵고 그만큼 강력하기에 꽃이라고 했겠지? 'use strict'; // Promise is a JavaScript object for asynchronous operation. // State: pending -> fulfilled or rejected // Producer vs Consumer // 1. Producer // when new Promise is created, the executor runs automatically. const promise = new Promise((resolve, reject) => ..

JS callback 입문!

출처. https://www.youtube.com/watch?v=s1vpVCrT8f4 callback 지옥이라서 호출 스택이 많이 쌓여서 지옥인가? 했는데 프로그래머에게 지옥의 의미는 유지, 보수, 수정이었다. error가 나는 부분이나, parameter를 가지고 와서 어디서 어떻게 쓰이는지 정말 보기 어려우니 지옥이였구나... 다음 편 promise를 어떻게 쓰는지가 중요할 것 같다. 'use strict'; // hoisting // Synchronous callback function printImmediately(print) { print(); } // Asynchronous callback function printWithDelay(print, timeout) { setTimeout(print..

JS JSON 입문!

출처. https://www.youtube.com/watch?v=FN_D4Ihs3LE&t=222s 예전에 프로젝트를 하면서 JSON을 썼었는데 JS에서 쓰니 깔끔한 것 같다. C#이나 Python, c++은 복잡했던 기억이... 콜백 함수를 parameter로 줄 수 있어서 stringify 된 value값을 다시 obj로 살리는 reviver는 정말 이름값 하는 것 같다. // JSON // JavaScript Object Notation // 1. Object to JSON // stringfy(obj) let json = JSON.stringify(true); console.log(json); json = JSON.stringify(['apple', 'banana']); console.log(jso..