Skip to content

Instantly share code, notes, and snippets.

View YounglanHong's full-sized avatar
🙏
Focused

YounglanHong

🙏
Focused
View GitHub Profile
@YounglanHong
YounglanHong / vanilla-js-cheatsheet.md
Created October 15, 2019 04:44 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
<a
href="https://github.com/YounglanHong/FinalProject_Custard"
target="_blank">
https://github.com/YounglanHong
</a>
/*
※ Error:
41:53 warning Using target="_blank" without rel="noreferrer" is a security risk: see
https://html.spec.whatwg.org/multipage/links.html#link-type-noopener react/jsx-no-target-blank
import React, { useState, useEffect } from 'react';
import { withRouter } from 'react-router-dom';
import axios from 'axios';
import Button from '@material-ui/core/Button';
axios.defaults.withCredentials = true;
// GetMsg
import React, { useState } from 'react';
import { withRouter } from 'react-router-dom';
import axios from 'axios';
import Button from '@material-ui/core/Button';
axios.defaults.withCredentials = true;
// SendMsg
import React, { useState } from "react";
import "./hook.css";
function Login() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
useEffect(() => {
console.log("useEffect1");
});
// A, An, The로 시작하는 경우, 해당단어들을 공백으로 대체
function strip(bandName) {
return bandName.replace(/^(a |the |an )/i, "").trim();
}
// sort 함수 내부에서 strip 함수로 인자를 감싸주면, 실제 데이터는 변화하지 않으면서 조건에 따라 정렬 가능
const sortedBands = bands.sort((a, b) => (strip(a) > strip(b) ? 1 : -1));
document.querySelector("#bands").innerHTML =
sortedBands
.map((band) => `<li>${band}</li>`)
.join("");
/* 사용자 지정 데이터 특성([data-time]) 예시
<li data-time="4:04">
Video 58
</li>
*/
const timeNodes = Array.from(document.querySelectorAll("[data-time]"));
//1️⃣ Map
const seconds = timeNodes
//2️⃣ Reduce
const seconds = timeNodes
.map((node) => node.dataset.time)
.reduce((acc, time) => {
const [mins, secs] = time.split(":").map(parseFloat);
time = mins * 60 + secs;
return acc + time;
}, 0);
class Coffee {
// constructor로 객체 초기화
constructor(menu, origin, roasting) {
this.menu = menu;
this.origin = origin;
this.roasting = roasting;
}
order() {
console.log(this.menu, "주문이 완료되었습니다")
}