If I have
Class Car {}
do I need to wrap that with our function closure? Do var's get hoisted to window? or just to the class? What about when transpiled? Does Traceur/babel turn it into a IIFE and let's into var's?
Do I need to:
(function(){
Class Car() {}
}());
To be safe?
You can have a look at what happens when Babel transpiles your code here
You don't need to use an IIFE unless you want to hide the class, and the var Class
that gets generated is hoisted as any variable: the declaration will take place at the start, but the assignement will take place in the original line.
And yes, Babel turns let
into var
, but it also takes care scoping works as expected with extra asignements. If you just want to write ES6 code and execute it you shouldn't have to worry about these details, just follow the ES6 (ES2015) standard.