====== ๐จ JavaScript ======
JavaScript๋ ์น ๋ธ๋ผ์ฐ์ ์์ ์คํ๋๋ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด๋ก, ๋์ ์ด๊ณ ์ธํฐ๋ํฐ๋ธํ ์น ํ์ด์ง๋ฅผ ๋ง๋ค ์ ์๊ฒ ํด์ค๋๋ค.
===== ๐ ์ ์ =====
**JavaScript**๋ ์น ๊ฐ๋ฐ์ ์ํ ๊ณ ๊ธ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์
๋๋ค. ์๋๋ ์น ๋ธ๋ผ์ฐ์ ์์๋ง ์คํ๋์์ง๋ง, ํ์ฌ๋ ์๋ฒ ์ฌ์ด๋(Node.js)์์๋ ์ฌ์ฉ๋๋ฉฐ, ๋ชจ๋ฐ์ผ ์ฑ๊ณผ ๋ฐ์คํฌํฑ ์ ํ๋ฆฌ์ผ์ด์
๊ฐ๋ฐ์๋ ํ์ฉ๋ฉ๋๋ค.
===== ๐ฏ ์ฃผ์ ํน์ง =====
**1. ๋์ ํ์
์ธ์ด**
- ๋ณ์์ ํ์
์ด ๋ฐํ์์ ๊ฒฐ์ ๋ฉ๋๋ค.
- ์ ์ฐํ ํ๋ก๊ทธ๋๋ฐ์ด ๊ฐ๋ฅํฉ๋๋ค.
**2. ์ด๋ฒคํธ ๊ธฐ๋ฐ ํ๋ก๊ทธ๋๋ฐ**
- ์ฌ์ฉ์ ์ํธ์์ฉ์ ๋ฐ์ํ๋ ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ์ง์ํฉ๋๋ค.
- ๋น๋๊ธฐ ํ๋ก๊ทธ๋๋ฐ์ด ์์ฐ์ค๋ฝ์ต๋๋ค.
**3. ๊ฐ์ฒด ์งํฅ ํ๋ก๊ทธ๋๋ฐ**
- ํ๋กํ ํ์
๊ธฐ๋ฐ ์์์ ์ง์ํฉ๋๋ค.
- ES6๋ถํฐ ํด๋์ค ๋ฌธ๋ฒ๋ ์ง์ํฉ๋๋ค.
===== ๐๏ธ ๊ธฐ๋ณธ ๋ฌธ๋ฒ =====
**๋ณ์ ์ ์ธ:**
// var (๊ตฌ์, ์ฌ์ฉ ๊ถ์ฅํ์ง ์์)
var oldWay = "๊ตฌ์ ๋ฐฉ๋ฒ";
// let (๋ธ๋ก ์ค์ฝํ)
let modernWay = "ํ๋์ ๋ฐฉ๋ฒ";
// const (์์)
const constantValue = "๋ณํ์ง ์๋ ๊ฐ";
**ํจ์ ์ ์:**
// ํจ์ ์ ์ธ
function traditionalFunction() {
return "์ ํต์ ์ธ ํจ์";
}
// ํจ์ ํํ์
const arrowFunction = () => {
return "ํ์ดํ ํจ์";
};
// ์ฆ์ ์คํ ํจ์
(function() {
console.log("์ฆ์ ์คํ");
})();
**๊ฐ์ฒด์ ๋ฐฐ์ด:**
// ๊ฐ์ฒด
const person = {
name: "ํ๊ธธ๋",
age: 30,
greet() {
return `์๋
ํ์ธ์, ${this.name}์
๋๋ค.`;
}
};
// ๋ฐฐ์ด
const numbers = [1, 2, 3, 4, 5];
const doubled = numbers.map(n => n * 2);
===== ๐ฎ DOM ์กฐ์ =====
**์์ ์ ํ:**
// ID๋ก ์ ํ
const element = document.getElementById('myId');
// ํด๋์ค๋ก ์ ํ
const elements = document.getElementsByClassName('myClass');
// CSS ์ ํ์๋ก ์ ํ
const element = document.querySelector('.myClass');
const elements = document.querySelectorAll('.myClass');
**์ด๋ฒคํธ ์ฒ๋ฆฌ:**
// ์ด๋ฒคํธ ๋ฆฌ์ค๋ ์ถ๊ฐ
element.addEventListener('click', function(event) {
console.log('ํด๋ฆญ๋จ!');
});
// ํ์ดํ ํจ์ ์ฌ์ฉ
element.addEventListener('mouseover', (event) => {
element.style.backgroundColor = 'red';
});
**DOM ์กฐ์:**
// ์์ ์์ฑ
const newElement = document.createElement('div');
newElement.textContent = '์๋ก์ด ์์';
// ์์ ์ถ๊ฐ
document.body.appendChild(newElement);
// ์์ ์ ๊ฑฐ
element.remove();
// ์์ฑ ์ค์
element.setAttribute('class', 'newClass');
===== ๐ ๋น๋๊ธฐ ํ๋ก๊ทธ๋๋ฐ =====
**์ฝ๋ฐฑ ํจ์:**
// ๋น๋๊ธฐ ์์
์์
setTimeout(() => {
console.log('3์ด ํ ์คํ');
}, 3000);
// AJAX ์์ฒญ
fetch('/api/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
**Promise:**
const myPromise = new Promise((resolve, reject) => {
// ๋น๋๊ธฐ ์์
setTimeout(() => {
const success = Math.random() > 0.5;
if (success) {
resolve('์ฑ๊ณต!');
} else {
reject('์คํจ!');
}
}, 1000);
});
myPromise
.then(result => console.log(result))
.catch(error => console.error(error));
**async/await:**
async function fetchData() {
try {
const response = await fetch('/api/data');
const data = await response.json();
return data;
} catch (error) {
console.error('๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ ์คํจ:', error);
}
}
// ์ฌ์ฉ
fetchData().then(data => console.log(data));
===== ๐๏ธ ๋ชจ๋ ์์คํ
=====
**ES6 ๋ชจ๋:**
// math.js
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;
export default class Calculator {
multiply(a, b) {
return a * b;
}
}
// main.js
import Calculator, { add, subtract } from './math.js';
console.log(add(5, 3)); // 8
console.log(subtract(10, 4)); // 6
const calc = new Calculator();
console.log(calc.multiply(6, 7)); // 42
**CommonJS (Node.js):**
// math.js
module.exports = {
add: (a, b) => a + b,
subtract: (a, b) => a - b
};
// main.js
const math = require('./math.js');
console.log(math.add(5, 3)); // 8
===== ๐ฏ ES6+ ๊ธฐ๋ฅ =====
**๊ตฌ์กฐ ๋ถํด ํ ๋น:**
// ๋ฐฐ์ด ๊ตฌ์กฐ ๋ถํด
const [first, second, ...rest] = [1, 2, 3, 4, 5];
// ๊ฐ์ฒด ๊ตฌ์กฐ ๋ถํด
const { name, age, ...otherProps } = person;
**ํ
ํ๋ฆฟ ๋ฆฌํฐ๋ด:**
const name = "ํ๊ธธ๋";
const greeting = `์๋
ํ์ธ์, ${name}๋!`;
const multiLine = `
์ฌ๋ฌ ์ค์
ํ
์คํธ๋ฅผ
์ฝ๊ฒ ์์ฑํ ์ ์์ต๋๋ค.
`;
**ํด๋์ค:**
class Animal {
constructor(name) {
this.name = name;
}
speak() {
return `${this.name}์ด(๊ฐ) ์๋ฆฌ๋ฅผ ๋
๋๋ค.`;
}
}
class Dog extends Animal {
speak() {
return `${this.name}์ด(๊ฐ) ๋ฉ๋ฉ ์ง์ต๋๋ค.`;
}
}
const dog = new Dog('๋ฐ๋์ด');
console.log(dog.speak()); // "๋ฐ๋์ด๊ฐ ๋ฉ๋ฉ ์ง์ต๋๋ค."
===== ๐ ๏ธ ๋๋ฒ๊น
=====
**์ฝ์ ๋ฉ์๋:**
console.log('์ผ๋ฐ ๋ก๊ทธ');
console.error('์๋ฌ ๋ฉ์์ง');
console.warn('๊ฒฝ๊ณ ๋ฉ์์ง');
console.info('์ ๋ณด ๋ฉ์์ง');
// ๊ฐ์ฒด ์ถ๋ ฅ
console.table([
{ name: 'ํ๊ธธ๋', age: 30 },
{ name: '๊น์ฒ ์', age: 25 }
]);
// ์ฑ๋ฅ ์ธก์
console.time('์์
์๊ฐ');
// ... ์์
์ํ
console.timeEnd('์์
์๊ฐ');
**๋ธ๋ ์ดํฌํฌ์ธํธ:**
===== ๐ ๊ด๋ จ ์ฉ์ด =====
* [[wiki:glossary:web_technologies:html|HTML]] - ๋งํฌ์
์ธ์ด
* [[wiki:glossary:web_technologies:css|CSS]] - ์คํ์ผ์ํธ
* [[wiki:glossary:web_technologies:dom|DOM]] - ๋ฌธ์ ๊ฐ์ฒด ๋ชจ๋ธ
* [[wiki:glossary:web_technologies:ajax|AJAX]] - ๋น๋๊ธฐ ํต์
* [[wiki:glossary:web_technologies:json|JSON]] - ๋ฐ์ดํฐ ํ์
* [[wiki:glossary:server_operations:nodejs|Node.js]] - JavaScript ๋ฐํ์
* [[wiki:glossary:game_development:phaser|Phaser.js]] - ๊ฒ์ ์์ง
* [[wiki:glossary:server_operations:socketio|Socket.IO]] - ์ค์๊ฐ ํต์
===== ๐ ๊ด๋ จ ๋ฌธ์ =====
* [[wiki:it:dream_of_enc:metaverse:phaser|Phaser.js ๊ฒ์ ์์ง]]
* [[wiki:it:dream_of_enc:metaverse:nodejs|Node.js ๋ฐฑ์๋ ์ค์ ]]
* [[wiki:glossary:web_technologies:css|CSS]] - ์คํ์ผ๋ง
* [[wiki:glossary:development_tools:git:github|GitHub]] - ์ฝ๋ ์ ์ฅ์
---
//์ด ํ์ด์ง๋ ์๋์ผ๋ก ์์ฑ๋์์ต๋๋ค.//