0

An ES6 class is a 'syntactic sugar' around the wellknown object-prototype based OOP, AFAIK. Therefore I'd expected to find class definitions in window just before tried this in a browser:

function Foo() {} Foo.prototype.fooFunction = function() {}; class Bar { barFunction(){} } console.log(window.Foo); // shows: function Foo() ... console.log(window.Bar); // shows: undefined !!! 

The latter shows undefined instead of function Bar()...

Where is the Bar object/function that represents the Bar class?

3
  • 2
    It's the same for let/const - that var variables (or functions) in the global scope get added to the global object is... a debatable legacy thing. Commented Jan 8, 2022 at 13:38
  • console.log(Bar) Commented Jan 8, 2022 at 13:38
  • Related: why don't const and let statements get defined on the window object. Commented Jan 8, 2022 at 13:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.