I have the following Javascript file:
class Coo { constructor() { } } function foo() { } Now if I load this into a browser (with a script tag), there is now a function window.foo defined. However, window.Coo is undefined.
So how does the scope of class work and how is it different from function?
In other words: Where do classes live?
classdefinitions don't add properties to the global object (which is, loosely speaking,windowon browsers). This is also true ofletandconstdeclarations. They create globals, but not properties on the global object. Older-style declarations (function,var) at global scope do create properties on the global object. When the new forms were being added, TC39 (the steering committee for JS) were trying to reduce the exposure of things.