<!--์ฆ์ ์คํ ํจ์-->
(function() {
//JavaScript ์ฆ์ ์คํ ํ ๋ด์ฉ ์
๋ ฅ
})();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app"></div>
<script>
var div = document.querySelector('#app');
var viewModel = {}; //๊ฐ์ฒด ์ ์ธ
//์ฆ์ ์คํ ํจ์๋ฅผ ํตํด ๋ ๋ค๋ฅธ ์ค์ฝํ์ ๋ฃ์ด์ค๋ค.
//๋๋ถ๋ถ์ ์คํ ์์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ด ํด๋น ํ์์ ๋๊ณ ์์
(function() {
function init()
{
Object.defineProperty(viewModel, 'str', {
//get: ์์ฑ์ ์ ๊ทผํ์ ๋์ ๋์์ ์ ์
get: function() {
console.log('์ ๊ทผ');
},
//set: ์์ฑ์ ๊ฐ์ ํ ๋นํ์ ๋์ ๋์์ ์ ์
set: function(newValue)
{
console.log('ํ ๋น', newValue);
rendoer(newValue);
}
});
}
function rendoer(value)
{
div.innerHTML = value;
}
init();
})();
</script>
</body>
</html>