Coding - Algo/Nodejs
[Nodejs] Property 사용
jainn
2021. 6. 9. 16:54
728x90
property 와 method의 관계
마이크로소프트에서 정의한 프로퍼티와 메소드에 따르면,
properties store data for an object
methods are actions an object can be asked to perform
property는 object를 위해서 데이터를 저장한다.
method는 object가 요청 받을 수 있는 액션이다.
라고한다.
property 사용 전
function templateHTML(title, list, body, control){
return `
<!doctype html>
<html>
<head>
<title>WEB1 - ${title}</title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="/">WEB</a></h1>
${list}
${control}
${body}
</body>
</html>
`;
}
var template = templateHTML(title, list, `<h2>${title}</h2>${description}`, `<a href="/create">create</a>`);
response.writeHead(200);
response.end(template);
property 사용 후(객체화)
var template = {
HTML: function(title, list, body, control){
return `
<!doctype html>
<html>
<head>
<title>WEB1 - ${title}</title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="/">WEB</a></h1>
${list}
${control}
${body}
</body>
</html>
`;
}
}
var html = template.HTML(title, list, `<h2>${title}</h2>${description}`, `<a href="/create">create</a>`);
response.writeHead(200);
response.end(html);
반응형