Skip to content

Instantly share code, notes, and snippets.

View sorie's full-sized avatar
💭
I may be slow to respond.

lala sorie

💭
I may be slow to respond.
  • Seoul or Jeju island
View GitHub Profile
let constraints = {video: true};
(async () => {
try{
await navigator.mediaDevices.getUserMedia(constraints).then(function (param, streams) {
throw error
if (getLocalStream) {
/*mediaDevices체크 */
let videoTracks = streams.getVideoTracks();
let audioTracks = streams.getAudioTracks();
console.log('dev test selected camera : ' + videoTracks[0].label);
@sorie
sorie / gist:ac2a8acf106e3b4387955289aec7385c
Created July 2, 2021 05:14
ES6 (2015) ~ ES11(2020) 핵심정리
//Shorthend property names
//변수명과 키값이 같은 경우 생략이 가능하다.
const name = 'Sori';
const age = '32';
const sori = {
name: name,
age: age
};
@sorie
sorie / gist:46c437f0400d9dad8d598731e8c6ae05
Created July 1, 2021 09:00
navigator.mediaDevices.enumerateDevices() will return an empty label
/**
navigator.mediaDevices.enumerateDevices() will return an empty label attribute value
if the permission for accessing the mediadevice is not given.
Try using it after getUserMedia.
**/
(async () => {
await navigator.mediaDevices.getUserMedia({audio: true, video: true});
let devices = await navigator.mediaDevices.enumerateDevices();
console.log(devices);
@sorie
sorie / gist:928111dec1107e698466142667c15680
Created July 1, 2021 08:52
json에 대한 모르던 사실
/**
json 모르던 사실
1. json안에서 함수사용가능하지만 stringify후 object로 바꾸면 함수는 사라진다.
2. stringify사용시 특정 값만 나오게 할수 있다.
3. stringify사용시 콜백함수를 사용할 수 있다.
**/
json = JSON.stringify(rabbit);
json = JSON.stringify(rabbit, ['name','color','size']);
json = JSON.stringify(rabbit, (key, value) => {
/**
1. 프로미스를 반환할 수도 있다.
2. then후에 반아오는 변수가 하나일 경우는 생략할 수 있다.
**/
const getHen = () =>
new Promise((resolve, reject) => {
setTimeout(() => resolve('닭'), 1000);
});
@sorie
sorie / gist:9aa645f5ec1202c794f7b2588240347e
Created July 1, 2021 08:50
async vs differ & usestrict사용이유
head안에 async를 넣으면 html parcing과 병렬로 실행된다.
head안에 differ를 넣으면 html parcing을 끝내고 실행된다.
usestrict 사용
typescript를 사용할때는 필요없지만
javascript는 많이 유연한 언어로 ecmascript5를 사용하겠다는 이야기
예를 들어 선언되지도 않은 변수를 불러와도 문제가 없었지만 usestrict를 사용하면 에러가 발생한다.더욱 엄격해지는것.
@sorie
sorie / gist:94ff1fe03f9914993be48252576eb795
Last active July 1, 2021 08:49
async/await 와 Promise#then
async function getApple() {
await delay(1000);
return '사과';
}
async function getBanana() {
await delay(1000);
return '바나나';
}
@sorie
sorie / gist:25ae00ead81411d8fd50d933851e29b5
Last active July 1, 2021 08:38
Check await order when trying/catch
(async () => {
try{
await (() => {
console.log( 'try await');
throw error;
console.log('after throw error');
})();
// throw error;
// await (() =>{console.info('after throw error')})();
return '사과';
@sorie
sorie / gist:fff0078770a222728debe66ac8c3e669
Created June 25, 2021 01:32 — forked from chad3814/gist:2924672
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]
@sorie
sorie / dom_performance_reflow_repaint.md
Created January 29, 2021 07:35 — forked from faressoft/dom_performance_reflow_repaint.md
DOM Performance (Reflow & Repaint) (Summary)

DOM Performance

Rendering

  • How the browser renders the document
    • Receives the data (bytes) from the server.
    • Parses and converts into tokens (<, TagName, Attribute, AttributeValue, >).
    • Turns tokens into nodes.
    • Turns nodes into the DOM tree.
  • Builds CSSOM tree from the css rules.