선택자 뭉치와 일치하는 문서 내 첫 번째 element 반환, 일치하는 요소가 없으면 null 반환
document.querySelector(selectors);
지정된 셀렉터 그룹에 일치하는 document의 element 리스트를 나타내는 정적(살아 있지 않은) NodeList 를 반환
document.querySelectorAll(selectors);
function(self) 선언할 경우 this를 self로 변경
단, 사용할 때는 function(this)로 써야함
// 함수 선언
function nightDayHandelr(self) {
var target = document.querySelector('body');
if(self.value === 'night') {
target.style.backgroundColor = 'black';
target.style.color = 'white';
self.value = 'day';
}
}
// 함수 사용
nightDayHandelr(this);
// 배열 생성
var coworkers = {
"programmer":"egoing",
"designer":"leezche"
};
// 함수 선언
coworkers.showAll = function() {
for(var key in this) {
document.write(key+' : '+this[key]+'<br>');
}
}
// 함수 사용
coworkers.showAll();
객체는 대문자로 시작, 함수는 소문자로 시작
// 객체 선언
var Body = {
setColor:function(color) {
document.querySelector('body').style.color = color;
},
setBackgroundColor:function(color) {
document.querySelector('body').style.backgroundColor = color;
}
// 객체 사용
Body.setBackgroundColor('black');
Body.setColor('white');
파일시스템을 가져옴
var fs = require('fs');
파일을 읽어옴
첫번재 인자는 읽을 파일경로(현재 실행중인 디렉토리 기준 path)
두번째 인자는 문자 character
세번째 인자는 콜백함수, data가 읽은 file의 데이터
fs.readFile(`data/${queryData.id}`, 'utf8', (err, description)=>{
코드
})
파일 목록을 가져옴 → 배열 형태
fs.readdir('./data', (err, filelist)=>{
코드
})
파일을 생성함
첫번째 인자는 파일명
두번째 인자는 파일 내용
세번째 인자는 콜백함수
fs.writeFile(`data/${title}`, description, 'utf8', (err)=>{
코드
})
파일 이름 또는 내용을 수정함
첫번째 인자는 파일명
두번째 인자는 파일 내용
세번째 인자는 콜백함수
fs.rename(`./data/${title_ori}`, `./data/${title}`, ()=>{
코드
})
파일을 삭제함
첫번째 인자는 파일경로+파일명
두번째 인자는 콜백함수
fs.unlink(`data/${id}`, (err)=>{
코드
})
네트워크 상에서 자원이 어디 있는지를 알려주기 위한 규약
url 정보를 객체로 가져와서 분석하거나, url 객체를 문자열로 바꿔주는 기능
var url = require('url');
객체 : { 키 : 값 } 형식
url 문자열을 입력하면 url 객체를 만듦, ↔ format()
url 객체를 입력하면 url 문자열을 반환 ↔ parse()
상대 url을 절대 url로 변경