์ด๋ ฅ์์ ๊นํ ์ด์ผ๊ธฐ.. ๋ฅผ ๋จผ์ ๋ค์๋ค.
๊ฐ์ฅ ์ค์ํ๊ฒ ๋ฐฐ์์ผ ํ ๊ฒ์ ํ์ด์ง ๊ตฌํ.
string.repeat(10)
Array.from('a'.repeat(10)) // ์ด๋ฐ์์ผ๋ก ๋ง์ด ์ฌ์ฉํ๋ค.
Array(10) // ์์ ํ ์๋ฌด๊ฒ๋ ๋ค์ด์์ง ์์ undefined๋ ์๋ค์ด๊ฐ Array ์์ฑ.
Array(10).fill(0) // 10๊ฐ์ ์ ๋ถ 0 ์ฑ์.
Array(10).fill(0).map((value, index) => value + index)
// reduce ๋ ๋ง์ด ์์.
arr.reduce((sum, current) => sum + current)
let s = 0
[1, 2, 3, 4, 5].forEach(i => s+i)
[1, 2, 3, 4, [1, 2, [1, 2, 3]]].flat() // ํ๋จ๊ณ ํผ์ณ์ค
[1, 2, 3, 4, [1, 2, [1, 2, 3]]].flat().flat() // ๋๋จ๊ณ
[1, 2, 3, 4, [1, 2, [1, 2, 3]]].flat(2) // ๋๋จ๊ณ
[1, 2, 3, 4, [1, 2, [1, 2, 3]]].flat(Infinity) // ์ญ ๋ค ํผ์ณ์ค
2 ** 3 ** 2 // ์ฐ๊ฒฐํฉ์ด๋ฏ๋ก ์ฃผ์ํ์.
s.split(' ') // ' ' ๊ธฐ์ค์ผ๋ก ์๋ผ์ array๋ฅผ ๋ง๋ค์ด์ค๋ค.
// map ์ ๋ฐํ๊ฐ์ด ์๊ณ , forEach ๋ ๋ฐํ๊ฐ ์์ด ํจ์๋ง ์คํํด์ค.
const arr = '12345'.split('').forEach(x => parseInt(x))
let today = new Date()
today.toISOString()
Math.max([1, 2, 10, 6, 7]) // NaN
Math.max(...[1, 2, 10, 6, 7]) // 10 ํผ์ณ์ผ ์๋ ค์ค.
Math.max.apply(null, [1, 2, 10, 6, 7]) // ... ๋ฑ์ฅ ์ ์ ์ด๋ ๊ฒ ์ฌ์ฉํ๋ค.
Math.PI
Math.SQRT2 // root 2
Number.MAX_SAFE_INTEGER
Number.MIN_SAFE_INTEGER
Number.EPSILON // javascript์์ ๋ ์ ์๋ ์ค์ฐจ ๋ฒ์.
์๋ js๋ ์ต๋ํ ์ค๋ฅ๋ฅผ ๋ด์ง ์๊ฒ ์ค๊ณ๋์ด ์๋๋ฐ ํด๋น ๋ถ๋ถ๋ค์ ์๊ฒฉํ๊ฒ ์ฌ์ฉํ๊ณ ์ถ์ผ๋ฉด, 'use strict' ๋ฅผ ์ด์ฉํด์ ์๊ฒฉํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.
js ๋ค๋ฅธ ํ์ผ์ ๋ณ์๋ ์ฐธ์กฐ ๊ฐ๋ฅํ๋ค.
function sayName() {
console.log(this.name)
}
let peter = {
name: 'Peter Parker',
sayName: sayName
sayName2: function (name1, name2) {
console.log(this.name + ' is' + name1 + ' or ' + name2);
}
}
let bruce = {
name: 'Bruce Wayne',
sayName: sayName
}
sayName() // this == window
peter.sayName() // this == peter
let peter2 = {
name: 'Peter Parker',
// bind : this๊ฐ ๊ณ ์ ๋ ํจ์๋ฅผ ๊ฐ์ ธ์๋ฒ๋ฆผ.
sayName: sayName.bind(bruce)
}
// call: ๋ค๋ฅธ object์ ํจ์๋ฅผ ๊ฐ์ ธ์ค๋๋ฐ ์ฌ์ ์ ํ์ง ์๊ณ ๊ฐ์ ธ์ด.
peter.sayName.call(bruce) // peter ํจ์์ธ๋ฐ this == bruce
// apply: ํจ์๋ฅผ ๊ฐ์ง๊ณ ์ค๋๋ฐ, ์ธ์๋ฅผ ์ ๋ฌ.
peter.sayName2.apply(bruce, ['batman', 'richman']) // peter ํจ์์ธ๋ฐ this == bruce
์ ๋ณด ์๋์ ์ํด ์ฌ์ฉ.
function ์ ๊ณฑ(x) {
function ์น์(y) {
return y ** x
}
// ํจ์๋ฅผ return
return ์น์
}
์ ๊ณฑ(2)(10) //100
์ผ๋ฐ ํจ์์ ์ฐจ์ด ์์. ์ฒซ ๊ธ์๋ฅผ ๊ผญ ๋๋ฌธ์๋ก ์ฐ์.
JavaScript์์ ์ฌ์ฉํ๋ ๋ฐ์ดํฐ ํ์. JS์์ ์ฌ์ฉํด์ JSON ์ด์๋ค๋..
๊ทธ ์ ์๋ xml ํ์์ ์ฌ์ฉํ๊ธฐ๋ ํ๋ค.
// key ๊ฐ๋ ์๋ฐ์ดํ๋ผ๋ ๊ฒ์ ์ ์ํ์.
{
"squadName": "์ํผํ์ด๋ก",
"members": [
{
"name": "์์ด์ธ๋งจ",
"age": 29,
"๋ณธ๋ช
": "ํ ๋ ์คํํฌ"
},
{
"name": "ํํฌ",
"age": 39,
"๋ณธ๋ช
": "๋ถ๋ฅด์ค ๋ฐฐ๋"
}
]
}
JSON.stringify(user, null, 4); // ๊ณต๋ฐฑ ๋ฌธ์ 4๊ฐ๋ฅผ ์จ์ ๋ค์ฌ์ฐ๊ธฐ ํ ํํ๋ก ๋ง๋ค์ด์ค.
var arr = [1, 2, 3, 4]
var arrString = JSON.stringify(arr)
JSON.parse(arrString)
JSON ๋ฐ์์์ ์ฒ๋ฆฌํ๊ธฐ
function sortTable(key) { if (click) { click = false; data.sort((a, b) => (a[key] > b[key] ? -1 : (a[key] < b[key]) ? 1 : 0)); } else { click = true; data.sort((a, b) => (a[key] < b[key] ? -1 : (a[key] > b[key]) ? 1 : 0)); } renderTable(data); } // function renderTable(data) { let tbodyData = []; for (const iterator of data) { // console.log(iterator); tbodyData.push(` <tr> <th>${iterator.index}</th> <th>${iterator.picture}</th> <th>${iterator.name}</th> // ... ์๋ต. </tr> `) const tbody = document.querySelector('tbody'); tbody.innerHTML = tbodyData.join(''); } }
์ ๋ํด ๊ณต๋ถํ๋ค.
์ฝ๋๋ฅผ ์๋ฒฝ ์ดํดํ๋ ค๊ณ ํ์ง๋ ์๊ณ ์ฐ๋จนํ๋ ๋๋์ผ๋ก ๋ค์ด๋ดค๋ค. ๊ทธ๋ฅ JavaScript ๋ค์ ๋๋ (์ต์ ์ ์๊ฒผ๋ค๊ณ ํ๋ ๋ฌธ๋ฒ๋ค์ด) Swift์ ์๋ ๋ฌธ๋ฒ์ด ๋ง์์ ์ํฅ์ ๋ง์ด ๋ฐ์๊ตฌ๋ ์ถ์๋๋ฐ, ๋ฆฌ์กํธ์ ์ต์ ๋ฌธ๋ฒ๋ค๊น์ง๋ Swift์์ ๋ณด์ด๋ ๊ตฌ์กฐ์ ๋ฌธ๋ฒ์ด๋ผ๋๊ฒ ์ ๊ธฐํ๋ค. Swift5... ์ต์ ์ธ์ด๊ฐ ๋ง๊ตฌ๋..
์ ๋๊ฐ ๊ธฐ์ต์ ๋จ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฐ๋๋ผ๋ก ์ง๋ฉด 10์ค๋ก ์งค ์ฝ๋๋ฅผ ์ดํดํ๊ธฐ ์ฌ์ด ๊ตฌ์กฐ๋ก 3์ค ์ด๋ ๊ฒ ์งค ์ ์๋ ๊ฒ์ด ์ธ์์ ์ด์๋ค.