Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsSet() seems to not change at all when transpiled to old JavaScript
I ran this code through the babel online transpiler. It changed the let
keywords to var
but it didn't change Set()
at all. Why is that? How long has Set()
been around?
2 Answers
Ken Howard
Treehouse Guest TeacherThe feature has been implemented in most browsers for a while but it is new to the ECMA specification.
Specification: http://www.ecma-international.org/ecma-262/6.0/#sec-set-constructor
Here's the browser compatibility list: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Browser_compatibility
Lars Reimann
11,816 PointsThis is because Babel only changes new syntax like destructuring or let and not new library functionality. Older browsers understand the line var classroom = new Set();
just fine, provided that a Set constructor exists. To make this constructor available, you need to include a polyfill.
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsBrendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsCool, thanks.