Skip to content

Commit

Permalink
better ES3 Map poly + link to es5-shims
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Oct 4, 2020
1 parent fa32ee6 commit 107e0ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/es3.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ module.exports = code => {
code = `// [ES3-Set-Polyfill
function Set(I){this.clear();if(I){this._k=I.slice(0);this.size=I.length}}
Set.prototype["delete"]=function(k){var _k=this._k,i=_k.indexOf(k),h=-1<i;if(h){_k.splice(i,1);this.size--;}return h};
Set.prototype.add=function(k,v){var _k=this._k,i=_k.indexOf(k);if(-1<i)_k[i]=k;else{_k.push(k);this.size++}return this};
Set.prototype.clear=function(){this._k=[];this.size = 0};
Set.prototype.has=function(k){return -1<this._k.indexOf(k)};
Set.prototype.add=function(k,v){var _k=this._k,i=_k.indexOf(k);if(-1<i)_k[i]=k;else{_k.push(k);this.size++}return this};
Set.prototype.entries=function(){for(var _k=this._k,e=[],i=0;i<this.size;i++)e[i]=[_k[i],_k[i]];return e};
Set.prototype.keys=function(){return this._k.slice(0)};
Set.prototype.values=function(){return this._k.slice(0)};
Expand All @@ -80,6 +80,7 @@ ${code}`;
function Map(I){this.clear();if(I){for(var i=0;i<I.length;i++){this._k.push(I[i][0]);this._v.push(I[i][1])}this.size=I.length}}
Map.prototype["delete"]=function(k){var _k=this._k,i=_k.indexOf(k),h=-1<i;if(h){_k.splice(i,1);this._v.splice(i,1);this.size--}return h};
Map.prototype.clear=function(){this._k=[];this._v=[];this.size=0};
Map.prototype.has=function(k){return -1<this._k.indexOf(k)};
Map.prototype.get=function(k){var i=this._k.indexOf(k);return -1<i?this._v[i]:void 0};
Map.prototype.set=function(k,v){var _k=this._k,i=_k.indexOf(k),h=-1<i;this._v[h?i:(_k.push(k)-1)]=v;if(!h)this.size++;return this};
Map.prototype.entries=function(){for(var e=[],i=0;i<this.size;i++)e[i]=[this._k[i],this._v[i]];return e};
Expand Down
4 changes: 3 additions & 1 deletion brainstorming.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ To be able to target every possible env, these are major restrictions to what's

If the target is *JS*, but *not* the *ES3* version of it, any code that won't follow previous convention will still be valid, cleaned up, and work as expected.

Most restrictions and definitions, in such case, will be mostly vaporware, but if the target is *ES3* you are in charge of providing all polyfills that are needed. See *es5 shims* good old library for that, but thi sproject doesn't grant stuff not meant to work out of the box will work.
Most restrictions and definitions, in such case, will be mostly vaporware, but if the target is *ES3* you are in charge of providing all polyfills that are needed, except for *Set* and *Map*, which are automatically provided when needed.

See [es5-shim](https://github.com/es-shims/es5-shim) good old library for other polyfills.

## As main program

Expand Down

0 comments on commit 107e0ce

Please sign in to comment.