var assert = require('assert'); describe('ê°ì²´', function(){ var person; beforeEach(function(){ person = new Object(); person.ì´ë¦ = 'ì´ì±ì£¼'; person.ì´ë©ì¼ = '[email protected]'; }); it('ìì± í¬í¨ ì¬ë¶', ()=>{ assert(person.ì´ë¦); assert(person['ì´ë©ì¼']); assert(!person.í¸ìí°); // ìì¸ê° ë°ìíì§ ììµëë¤. person.í¸ìí° = '@LeeSeongjoo'; assert(person.í¸ìí°); }); it('ë³ìì ê°ì²´ ìì±', ()=>{ person.x = 'x'; delete person.x; assert(!person.x); delete person; assert(person); }); it('í¨ìì ë©ìë', ()=>{ var ì¬ë = { ì´ë¦: 'ì´ì±ì£¼', ìê°í기: function(){ return `ì ì´ë¦ì ${this.ì´ë¦}ì ëë¤.`; } }; assert('ì ì´ë¦ì ì´ì±ì£¼ì ëë¤.', ì¬ë.ìê°í기()); }); it('ìì±ì ìì', function(){ assert('ì´ë¦' in person); assert('ì´ë©ì¼' in person); assert(person.hasOwnProperty('ì´ë¦')); assert(person.hasOwnProperty('ì´ë©ì¼')); assert(!person.hasOwnProperty('toString')); assert(!person.hasOwnProperty('hasOwnProperty')); }); it('ìì± ëì´', function(){ var ìì±ëª©ë¡ = Object.keys(person); assert.deepEqual(['ì´ë¦', 'ì´ë©ì¼'], ìì±ëª©ë¡); var ìì±ë¤ = []; for(var ìì± in person){ ìì±ë¤.push(ìì±) } assert.deepEqual(ìì±ëª©ë¡, ìì±ë¤); }); it('ìì±ì ì í', function(){ person = { ì´ë¦: 'ì´ì±ì£¼', get ì본(){ return this._ì본; }, set ì본(ê°){ if(ê° < 0){ throw new Error('ì본ê°ì ììê° ë ì ììµëë¤.'); } if(isNaN(ê°)){ throw new Error('ì«ìê°ì´ ìëëë¤.'); } this._ì본 = ê°; } }; person.ì본 = 100; assert.equal(100, person.ì본); assert.throws(function(){ person.ì본 = -1000; }, Error); assert.throws(function(){ person.ì본 = 'ë°±ë§ì'; }, Error); }) describe('ìì± ì¤ì ', function(){ describe('ë°ì´í° ìì±', function(){ it('enumerable', function(){ Object.defineProperty(person, 'ì´ë©ì¼', { enumerable: false }); var ìì±ëª©ë¡ = Object.keys(person); assert.deepEqual(['ì´ë¦'], ìì±ëª©ë¡); }); it('configurable', function(){ Object.defineProperty(person, 'ì´ë¦', { configurable: false, enumerable: true }); delete person.ì´ë¦; assert(person.ì´ë¦); // ì¤ì ë°©ì§ í´ì ìë assert.throws(()=>{ Object.defineProperty(person, 'ì´ë¦', { configurable: true, enumerable: true }); }, TypeError); }); it('writable', function(){ Object.defineProperty(person, 'ì´ë¦', { enumerable: true, writable: false }); person.ì´ë¦ = 'ê¹ì±ì£¼'; assert.equal('ì´ì±ì£¼', person.ì´ë¦); }); it('value', function(){ Object.defineProperty(person, 'í¸ìí°', { value: '@LeeSeongjoo', enumerable: true, configurable: true, writable: true }); assert.equal('@LeeSeongjoo', person.í¸ìí°); }); }); describe('ì ê·¼ì ìì±', function(){ it('ì¤ì ', function(){ Object.defineProperty(person, 'ì본', { set: function(ê°){ this._ì본 = ê°; }, get: function(){ if(!this._ì본) return 0; return this._ì본; } }); assert.equal(0, person.ì본); person.ì본 = 100; assert.equal(100, person.ì본); }); it('enumerable', function(){ Object.defineProperty(person, 'ì본', { configurable: true, set: function(ê°){ this._ì본 = ê°; }, get: function(){ if(!this._ì본) return 0; return this._ì본; } }); assert.equal(0, person.ì본); Object.defineProperty(person, 'ì본', { enumerable: false }); assert(!person.ì본); }); it('configurable', function(){ Object.defineProperty(person, 'ì본', { enumerable: true, configurable: true, set: function(ê°){ this._ì본 = ê°; }, get: function(){ if(!this._ì본) return 0; return this._ì본; } }); Object.defineProperty(person, 'ì본', { enumerable: true, configurable: false, }); assert.equal(0, person.ì본); delete person.ì본; assert.equal(0, person.ì본); }); }); }); describe('ê°ì²´ ì¤ì ', function(){ it('ìì± ì¶ê° ì¤ì ', function(){ assert(Object.isExtensible(person)); Object.preventExtensions(person); person.ì í = '010-1234-5678'; assert(!person.ì í); // 기존 ì¤ì ì ëí ìì ì ê°ë³ ìì± ì¤ì ì ë°ë¦ ëë¤. delete person.ì´ë©ì¼; assert(!person.ì´ë©ì¼); // "기존" ì¤ì ì´ë¼ê³ í´ë ìì ëë©´ // ì´ì ë "기존" ì¤ì ì´ë¼ í ì ììµëë¤. person.ì´ë©ì¼ = 'seongjoo@'; assert(!person.ì´ë©ì¼); }); it('seal: ì¶ê°/ìì ë°©ì§', function(){ Object.seal(person); delete person.ì´ë¦; assert(person.ì´ë¦); person.ì í = '1234'; assert(!person.ì í); }); it('freeze: ì¶ê°/ìì /ì°ê¸° ë°©ì§', function(){ Object.freeze(person); person.ì í = '1234'; assert(!person.ì í); delete person.ì´ë¦; assert(person.ì´ë¦); person.ì´ë¦ = 'ê¹ì±ì£¼'; assert.equal('ì´ì±ì£¼', person.ì´ë¦); }); }); describe('í¨ìì this', function(){ var ìê°; function ìê°í기(){ return `ìë íì¸ì, ${this.ì´ë¦}ì ëë¤.`; } it('call', function(){ ìê° = ìê°í기.call(person); assert.equal('ìë íì¸ì, ì´ì±ì£¼ì ëë¤.', ìê°); }); }); });