ÀÚ¹Ù½ºÅ©¸³Æ®¿¡¼ Á¤ÀûÀÎ ÇÔ¼ö´Â Áö¿ø ÇÏÁö¸¸ Á¤ÀûÀÎ º¯¼ö´Â ¿ìȸÀûÀ¸·Î »ç¿ëÇØ¾ß ÇÑ´Ù. ±ä ¼³¸í ¾øÀÌ ¹Ù·Î ½ÇÇàµÇ´Â Äڵ带 ºÐ¼®ÇØ º¸ÀÚ. Á¤Àû Ŭ·¡½º³ª ÇÁ·ÎÅä ŸÀÔ µ¥ÀÌÅÍ º¯¼ö´Â ClassBody ¼±¾ð ¿ÜºÎ¿¡¼ Á¤ÀÇ µÇ¾î¾ß ÇÑ´Ù. ÀÌ ÇÑÁÙÀº ¸¹Àº°ÍÀ» ³»Æ÷ÇÏ°í ÀÖ´Ù. class People {
static sayName() { console.log('myname is ' + People.myname); } } People.myname = 'ken'; People.sayName(); °á°ú) myname is ken ¾Æ·¡ ±¸¹®µµ À§¿Í °°ÀÌ ½ÇÇà µÈ´Ù. class People {
static sayName() { console.log('myname is ' + this.myname); } } °á°ú) myname is ken ´ÙÀ½À» ½ÇÇàÇØ º¸ÀÚ. class People {
constructor() { this.nickname = 'none name'; } static sayName() { console.log('myname is ' + this.myname); } } People.myname = 'ken'; People.sayName(); let people = new People(); console.log(people); »ý¼ºÀÚ ³»ºÎ¿¡¼ ¼±¾ðµÈ º¯¼ö this.nicknameÀº __proto__ ¼Ó¼ºÀÌ ¾Æ´Ï´Ù. »ý¼ºÀÚ ¿ÜºÎ¿¡¼ ¼±¾ðµÈ this.mynameÀº __proto__ ¼Ó¼ºÀÌ´Ù. ¿ÜºÎ¿¡¼ ¼±¾ðÇÑ º¯¼ö´Â __proto__ ¼Ó¼ºÃ³·³ ½ÇÇàµÈ´Ù. À§ÀÇ __proto__ ¼Ó¼ºÀ» ÀÀ¿ëÇؼ °£´ÜÇÑ ½Ì±ÛÆÐÅÏÀ» ¸¸µé¾î º¸ÀÚ. RunState.createInstance : ½Ì±ÛÅÏ ÀνºÅϽº¸¦ »ý¼ºÇÑ´Ù. RunState.instance : ½Ì±ÛÅÏ ÀνºÅϽº¸¦ getter, setter·Î Á¢±ÙÇÑ´Ù. class RunState{
static get instance() { return this._instance; } static set instance(obj) { this._instance = obj; } static createInstance() { if(!RunState.instance) { console.log('create RunState Instance'); RunState.instance = new RunState(); } } constructor() { } enter(unit) { console.log('RunState enter'); } execute(unit, dt) { console.log('RunState execute'); } exit(unit) { console.log('RunState exit'); } } RunState.createInstance(); RunState.createInstance(); console.log (RunState.instance); °á°ú) create RunState Instance RunState RunState.createInstance ÇÔ¼ö¸¦ µÎ¹ø ½ÇÇàÇßÁö¸¸ ÀÌ¹Ì RunState°¡ »ý¼ºµÇ¾î ÀÖÀ¸¸é ¸¸µéÁö ¾Ê´Â´Ù. Âü°í) class¿¡¼ Á¤ÀûÀÎ º¯¼ö »ç¿ë https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Classes https://stackoverflow.com/questions/51381966/how-do-i-use-a-static-variable-in-es6-class class¿¡ ´ëÇØ https://scotch.io/tutorials/better-javascript-with-es6-pt-ii-a-deep-dive-into-classes class »èÁ¦ https://stackoverflow.com/questions/42175566/can-we-delete-es6-class class¿¡¼ private ¼±¾ðÇÏ´Â ¹æ¹ý https://gomugom.github.io/how-to-make-private-member/ |