diff --git a/cjs/index.js b/cjs/index.js index 6983934..1b50d60 100644 --- a/cjs/index.js +++ b/cjs/index.js @@ -2,11 +2,16 @@ try { new Map; } catch (o_O) { (function (i, dPs) {'use strict'; - var proto = (Map = function Map(iterable) { + var proto = dPs((Map = function Map(iterable) { dPs(this, {_k: {value: []}, _v: {value: []}}); if (iterable) iterable.forEach(add, this); - }).prototype; + }).prototype, {size: { + configurable: true, + get: function () { + return this._k.length; + } + }}); proto.clear = function () { var length = this._k.length; this._k.splice(0, length); diff --git a/esm/index.js b/esm/index.js index c53737c..db9326e 100644 --- a/esm/index.js +++ b/esm/index.js @@ -2,11 +2,16 @@ try { new Map; } catch (o_O) { (function (i, dPs) {'use strict'; - var proto = (Map = function Map(iterable) { + var proto = dPs((Map = function Map(iterable) { dPs(this, {_k: {value: []}, _v: {value: []}}); if (iterable) iterable.forEach(add, this); - }).prototype; + }).prototype, {size: { + configurable: true, + get: function () { + return this._k.length; + } + }}); proto.clear = function () { var length = this._k.length; this._k.splice(0, length); diff --git a/index.js b/index.js index 03aef6c..eec885b 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,16 @@ try { new Map; } catch (o_O) { (function (i, dPs) {'use strict'; - var proto = (Map = function Map(iterable) { + var proto = dPs((Map = function Map(iterable) { dPs(this, {_k: {value: []}, _v: {value: []}}); if (iterable) iterable.forEach(add, this); - }).prototype; + }).prototype, {size: { + configurable: true, + get: function () { + return this._k.length; + } + }}); proto.clear = function () { var length = this._k.length; this._k.splice(0, length); diff --git a/min.js b/min.js index 2b01637..22f076f 100644 --- a/min.js +++ b/min.js @@ -1,2 +1,2 @@ /*! (c) Andrea Giammarchi - ISC */ -try{new Map}catch(o_O){!function(t,i){"use strict";function n(t){this.set(t[0],t[1])}function s(i,n){return-1<(t=i._k.indexOf(n))}function e(t,i){return[t,this[i]]}var h=(Map=function(t){i(this,{_k:{value:[]},_v:{value:[]}}),t&&t.forEach(n,this)}).prototype;h.clear=function(){var t=this._k.length;this._k.splice(0,t),this._v.splice(0,t)},h["delete"]=function(i){var n=s(this,i);return n&&(this._k.splice(t,1),this._v.splice(t,1)),n},h.entries=function(){return this._k.map(e,this._v)},h.forEach=function(t,i){this._k.forEach(function(n,s){t.call(i,this._v[s],n,this)},this)},h.get=function(i){return s(this,i)?this._v[t]:void 0},h.has=function(t){return s(this,t)},h.keys=function(){return this._k.slice(0)},h.set=function(i,n){return this._v[s(this,i)?t:this._k.push(i)-1]=n,this},h.values=function(){return this._v.slice(0)},Map}(0,Object.defineProperties)} \ No newline at end of file +try{new Map}catch(o_O){!function(t,i){"use strict";function n(t){this.set(t[0],t[1])}function e(i,n){return-1<(t=i._k.indexOf(n))}function s(t,i){return[t,this[i]]}var h=i((Map=function(t){i(this,{_k:{value:[]},_v:{value:[]}}),t&&t.forEach(n,this)}).prototype,{size:{configurable:!0,get:function(){return this._k.length}}});h.clear=function(){var t=this._k.length;this._k.splice(0,t),this._v.splice(0,t)},h["delete"]=function(i){var n=e(this,i);return n&&(this._k.splice(t,1),this._v.splice(t,1)),n},h.entries=function(){return this._k.map(s,this._v)},h.forEach=function(t,i){this._k.forEach(function(n,e){t.call(i,this._v[e],n,this)},this)},h.get=function(i){return e(this,i)?this._v[t]:void 0},h.has=function(t){return e(this,t)},h.keys=function(){return this._k.slice(0)},h.set=function(i,n){return this._v[e(this,i)?t:this._k.push(i)-1]=n,this},h.values=function(){return this._v.slice(0)},Map}(0,Object.defineProperties)} \ No newline at end of file diff --git a/test/index.js b/test/index.js index c299f9b..ed7a9e3 100644 --- a/test/index.js +++ b/test/index.js @@ -36,9 +36,10 @@ function test() { var ws2 = new Map([[a, b]]); console.assert(ws1.has(a) === false); - console.assert(ws1.set(a, 123) === ws1); + console.assert(ws1.set(a, 456) === ws1); console.assert(ws1.set(a, 123) === ws1); console.assert(ws1.has(a) === true); + console.assert(ws1.size === 1); ws1.clear(); ws1.set(a, b); var entries = ws1.entries(); @@ -57,7 +58,6 @@ function test() { console.assert(values.length === 1); console.assert(values[0] === b); } - console.log(ws1.forEach); ws1.forEach(function (value, key, map) { console.assert(value === b); console.assert(key === a);