Comments (18)
those used to be Array
when I've first implemented this sham … specs made them Iterator
so it's pointless to polyfill them because no JS engine that does not supports natively Map and WeakMap can possibly support for/of
operator.
Does this answer your question?
from es6-collections.
Well that's true, but there are things like https://github.com/termi/es6-transpiler, that can manage for-of quite nicely. I haven't tried yet that and if there is some other blocker then nevermind this.
from es6-collections.
I believe that transpiler needs special syntax in order to support iterators but that's actually a valid point. I'll try to fix this somehow soon, stay tuned.
from es6-collections.
I had also found this one ... https://www.npmjs.org/package/es6-for-of
And if you need support for Symbol, this looks quite good ... https://www.npmjs.org/package/es6-symbol
from es6-collections.
Symbol done the right way are here
from es6-collections.
Ok, guess it doesn't matter that much. Till it's written according to specs, it should be good enough to use before it becomes stable in browsers.
from es6-collections.
OK, I've had a better look at what specs say and methods implemented here and there … it's more work than expected. If you are in a rush I might suggest an alternative, if not already linked in this project home. Apologies but I have not much time these days for extra maintenance :-(
from es6-collections.
Sure, let me know about alternative, it's not like everything would be dependent on this part :)
from es6-collections.
lurking around quickly, it seems that nobody got all three of them in (understandable, since WeakMap is not reliable) but the most complete polyfill seems to be the one included in es6-shim - it gives you fully specd Map
and Set
and should hopefully work with for/of
too.
I'll keep this updated in case I'll ever find some time to add these Iterator
based methods
from es6-collections.
Ping! Any chance of getting iterators? I literally can't use this lib because I want to use the built-in Set
and fallback to a polyfill but this lib acts differently than the spec.
from es6-collections.
I am pretty sure if the engine supports for/of you have native Set in there too, right ?
I am not sure if es6-shim would be a better, more obtrusive, polyfill for iterators too.
HHave a look: https://github.com/paulmillr/es6-shim/#safe-shims
from es6-collections.
So I'm actually using es6-set
right now, but you don't need for/of to iterate a Set:
var iterator = mySet.values();
var itVal;
while(!(itVal = iterator.next()).done) {
itVal.value;
}
Which is basically how you have to do it if you want to use Set
in browsers that implement it, and have that same code run with a polyfill (no transpiling).
from es6-collections.
if that's how you have to do it anyway, what are you gaining in terms of performance? why not just the following?
mySet.forEach(function (value) {
// do what you have to do
});
I think es6-shim is the right way to go for a better compatibility. Transpilers might even support es6-shim fix/implementation in order to work properly, this old module was meant to introduce basic collections, not the whole new Iterator logic.
Not sure I should fix it, it seems right now overlapping or duplicated with what es6-shi fixed already.
What do you think? Why you need this module to be fixed?
from es6-collections.
Actually, just ran a jsperf and it looks like using .forEach
and the while loop are both faster than using for/of, with the .forEach
method being the fastest:
http://jsperf.com/es6-collection-iteration/8
I wasn't aware that you were deprecating this module in favor of es6-shim, the reason I don't use es6-shim is because I can't include only the set polyfill or only the map polyfill. I basically have to include everything or nothing, which is lame. I am using es6-set
right now, which is 2K minified as opposed to es6-shim which is 30K. Note that I use CJS to organize my code, and since es6-shim has all the polyfills in a single file I can't include only a subset of it.
from es6-collections.
I am not necessarily deprecating this but I am not sure I want to fix the Iterator part. Iterator is a whole "thing" that if partially implemented coild break other code around. I rather stick with faster forEach
also because Iterator is meant to be used with generators. I don't see any advantage in terms of performance, readability, or amount of RAM and GC operations, that would make me use a for/of
instead of a forEach
... I don't see it practical, specially with Array-like structures.
Iterator is good, but not so useful with Sets or Maps, IMHO + I really don't have time to brng in a full Iterator logic that won't mess up with other possible polyfills that somehow fix Iterators in the whole env.
Hope this makes sense to you
from es6-collections.
@WebReflection Makes perfect sense, thanks for taking the time to explain it out. I still won't be using es6-shim for the foreseeable future, and I can't use for/of because I don't want to use a transpiler.
I want to use a set because the insert/unique check is much faster than an array, but the iteration is just so much slower (and that happens much more often in my case) so I may just switch to a pure array implementation.
from es6-collections.
if iteration is more frequent than inserting, how about this:
Array.prototype.pushUnique = function () {
for (var tmp, i = 0; i < arguments.length; i++) {
tmp = arguments[i];
if (this.indexOf(tmp) < 0) this.push(tmp);
}
return this.length;
};
you are penalized in insertion, but you won't compromise looping, which is the frequent operation.
from es6-collections.
@WebReflection Which is exactly what I am going to do, I was using a set because the insertion would be more performant but I didn't realize until now just how slow the iteration was :(
from es6-collections.
Related Issues (20)
- size is a property not a function HOT 1
- Set([iterable]) constructor only supports arrays, should support any Iterable HOT 2
- Memory leaks HOT 7
- Map.forEach: callback arguments flipped HOT 6
- Release notes for 0.3 -0.4.1? HOT 1
- keys/values/entries should return Iterator not Array HOT 10
- Various issues with using Object.is HOT 9
- es6-collections implementation should be used in Safari 7.1/8 HOT 6
- Browser support HOT 2
- shim es6-collections on IE11 HOT 3
- Add git tags HOT 3
- Map not working with NaN keys
- Error in IE11
- Map.clear() bug. HOT 7
- The feature check for Map in IE11 will throw exception
- The fix for IE11 issue not included in es6-collections.js HOT 5
- Make it available via bower HOT 6
- Not working in IE11/10/9 with aurelia HOT 2
- use of non standard properties in the test unit, versus `Array.from()` HOT 6
- Key equality HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from es6-collections.