jackmoore/autosize

map

Closed this issue · 3 comments

SCWR commented

I think map set function like:

var map = typeof Map === "function" ? new Map() : function () {
		var keys = [];
		var values = [];

		return {
			has: function has(key) {
				return keys.indexOf(key) > -1;
			},
			get: function get(key) {
				return values[keys.indexOf(key)];
			},
			set: function set(key, value) {
                              // if (keys.indexOf(key) === -1) {
				//       keys.push(key);
				//       values.push(value);
			     //  }
				this.delete(key);
				keys.push(key);
				values.push(value);
			},
			delete: function _delete(key) {
				var index = keys.indexOf(key);
				if (index > -1) {
					keys.splice(index, 1);
					values.splice(index, 1);
				}
			}
		};
	}();

What's the advantage here? To delete the element from keys/values just to add it right back is an inefficient thing to do.

why not to use Babel here? What's a reason of creating own polyfill?

Speaking for myself, I did not need an optimized and feature complete polyfill. I just needed some light object tracking for the nearly dead IE9/IE10 demographic. I assume a real polyfill will be much larger, which would be hard to justify including.