[출처] 자바스크립트 객체지향 (OOP)|작성자 롤링
JSON (객체표기법(JavaScript Object Notation) 방식
<script type="text/javascript" language="javascript">
Book = {
title : "sample"
, chapter : {
title : "title01"
, page : "24"
},
chapter2 : {
title : "title02"
, page : "50"
}
}
Book.chapter.title = "change_title";
alert(Book.chapter.title);
</script>
프로토타입(Prototype) 방식
<script type="text/javascript" language="javascript">
function Book(title, chapter1, chapter2)
{
this.title = title;
this.chapter1 = chapter1;
this.chapter2 = chapter2;
}
Book.prototype.toString = function() {
alert("title : " + this.title);
}
var book = new Book("book title", a, b);
function a() {
alert('a');
}
function b() {
alert('b');
}
//window.onload = book.chapter1;
//window.onload = book.chapter2;
window.onload = book.toString;
</script>