<SCRIPT> function getPlan(obj){ myDB=new Array('1¿ù','2¿ù','3¿ù','4¿ù','5¿ù','6¿ù','7¿ù','8¿ù','9¿ù','10¿ù','11¿ù','12¿ù'); return (obj.nowMonth+1)+' '+obj.dataType+'='+myDB[obj.nowMonth]+' È£ÃâÇß´Ù.'; } function dataCall(dataType,nowMonth,myOutput){ this.dataType=dataType; this.nowMonth=nowMonth; this.myOutput=getPlan(this); } pickData=new dataCall('¿ù°£ °èȹ',new Date().getMonth(),getPlan(this)); document.write(pickData.myOutput); </SCRIPT>
»ç¿ëÀÚ Á¤ÀÇ °³Ã¼¸¦ ¸¸µé±â À§Çؼ´Â ¸ÕÀú ƯÁ¤ À̸§À» °¡Áö°í ¼Ó¼ºµé°ú ¸Þ¼µéÀ» Á¤ÀÇÇÑ ±â´ÉÇÔ¼ö¸¦ ¸¸µé¾î¾ß ÇÑ´Ù.
br='<BR>'; function book(title,category,author){ this.title=title; this.category=category; this.author=author; } document.write('book=<FONT size=2>',book,'</FONT>',br);
±×¸®°í ´ÙÀ½ ¿¹Á¦¿Í °°ÀÌ °³Ã¼ÀÇ ÀνºÅº½º¸¦ ¸¸µé ¼ö ÀÖ´Ù.
mybook=new book('°íÇâ','¼Á¤','È«±æµ¿'); document.write('mybook.title="',mybook.title,'"',br); document.write('mybook.category="',mybook.category,'"',br); document.write('mybook.author="',mybook.author,'"',br);
ÇÑ °³Ã¼ÀÇ ¼Ó¼ºÀº ´Ù¸¥ °³Ã¼ÀÏ ¼ö ÀÖ´Ù. ÀÛ°¡µéÀÇ °³Ã¼¸¦ »ý¼ºÇÏ°í ´ÙÀ½°ú °°ÀÌ »ç¿ëÇÒ ¼ö ÀÖ´Ù.
¿©±â¼µµ ´Ù½Ã °³´ÉÇÔ¼ö¸¦ ±â¼úÇÑ ÈÄ¿¡ 'È«±æµ¿'¸¦ À§ÇÑ ±â´ÉÇÔ¼ö¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Ù.
function author(nicName,regiName,age){ this.nicName=nicName; this.regiName=regiName; this.age=age; } authorCall=new author('È«±æµ¿','±èÀϼö',43); document.write('authorCall.nicName="',authorCall.nicName,'"',br); document.write('authorCall.regiName="',authorCall.regiName,'"',br); document.write('authorCall.age="',authorCall.age,'"',br);
ÀÛ°¡ °³Ã¼¿Í ±×¿¡ »óÀÀÇÏ´Â ÀνºÅº½º°¡ ÀÌ¹Ì Á¤ÀǵǾî, 'book' °³Ã¼¿¡¼ ÀÛ°¡('author') ¼Ó¼ºÀº À̸¦ ÂüÁ¶ÇÒ °ÍÀÌ´Ù. 'mybook' ÀÛ°¡ÀÇ ³ªÀ̸¦ È£ÃâÇÒ ¼ö ÀÖ´Ù.
document.write(mybook.author,br); document.write(mybook.title,br); document.write(mybook.category,br,br); document.write(authorCall.nicName,br); document.write(authorCall.regiName,br); document.write(authorCall.age,br,br); newCall=new author(authorCall.nicName,authorCall.regiName,authorCall.age); document.write(newCall.age,br); newCall=new book(mybook.title,mybook.category,mybook.author); document.write(newCall.author,br);
°³Ã¼ÀÇ ¾î¶² ÀνºÅº½º¿¡ »õ·Î¿î ¼Ó¼ºÀ» Ãß°¡ÇÒ ¼ö ÀÖ´Ù. 'mybook' °³Ã¼¿¡ Á¦ÀÛ»ç('publisher') ¼Ó¼ºÀÌ ¿¹Á¦¿¡¼ Ãß°¡µÇ°í °ªÀÌ '¿ì¸®ÃâÆÇ»ç'·Î ÇÒ´çµÈ´Ù.
document.write(mybook.publisher,br); // Á¤Àǵȹ٠¾ø´Ù. mybook.publisher='¿ì¸®ÃâÆÇ»ç';// ¼Ó¼ºÀ» »õ·Î Á¤ÀÇÇÑ´Ù. document.write(mybook.publisher,br); // »õ·Î Á¤ÀÇÇÏ¿© Ãß°¡ÇÑ ¼Ó¼ºÀ» Ãâ·ÂÇÑ´Ù.
±×·¯³ª ÀÌÀü¿¡ Á¤ÀÇÇÑ °³Ã¼ÀÇ ¼Ó¼º¿¡ »õ·Î¿î ¼Ó¼ºÀ» Ãß°¡Çϱ⸦ ¿øÇÒ ¶§´Â prototype ¼Ó¼ºÀ» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. ¿¹Á¦´Â 'book' °³Ã¼ ŸÀÔ¿¡ 'publisher' ¼Ó¼ºÀ» Ãß°¡ÇÏ°í ±× Æ¯Á¤ ÀνºÅº½º¿¡ °ªÀ» '¿ì¸®ÃâÆÇ»ç'À¸·Î ÇÒ´çÇÑ´Ù.
document.write(book.prototype.publisher+br); // Á¤Àǵȹ٠¾ø´Ù. book.prototype.publisher=null; // »õ·Î Á¤ÀÇÇÏ¿© Ãß°¡ÇÑ ¼Ó¼ºÀ» ¾ø´Â °ÍÀ¸·Î ¼³Á¤ÇÑ´Ù. document.write(book.prototype.publisher+br); // »õ·Î Á¤ÀÇÇÏ¿© Ãß°¡ÇÑ ¼Ó¼ºÀ» Ãâ·ÂÇÑ´Ù. mybook.publisher='ÁÁÀº ÃâÆÇ»ç';// ¼Ó¼ºÀ» »õ·Î Á¤ÀÇÇÑ´Ù. document.write(mybook.publisher,br); // »õ·Î Á¤ÀÇÇÏ¿© Ãß°¡ÇÑ ¼Ó¼ºÀ» Ãâ·ÂÇÑ´Ù.