javascript - Polyfill for Internet Explorer ECMAScript Set constructor to allow iterable argument -
i wrote code using constructor described in mdn docs set object. unfortunately internet explorer 11 ignores iterable argument in constructor. had quick attempt @ trying override constructor (code below) no luck (set.prototype.size returns - 'this' not set object).
var testset = new set([0]); if (testset.size === 0) { //constructor doesnt take iterable argument - ie var oldproto = set.prototype set = function (iterable) { if (iterable) { iterable.foreach(this.add.bind(this)); } }; set.prototype = oldproto; }
is there way allow set constructor have iterable argument passed , still work in i.e. ? guess next best option create kind of factory method (set.create) returns new set instance.
you not creating new set
instance in code. if wanted overwrite constructor, should do
if (new set([0]).size === 0) { //constructor doesnt take iterable argument - ie const builtinset = set; set = function set(iterable) { const set = new builtinset(); if (iterable) { iterable.foreach(set.add, set); } return set; }; set.prototype = builtinset.prototype; set.prototype.constructor = set; }
Comments
Post a Comment