Unexpected value of this when inside a constructor function

Viewed 24

I have this code:

const foo = function() {
  console.log(this) // foo {}

  function bla() {
    console.log(this) // Window {}
  }
  bla()
}

let a = new foo()

Why does the first console.log(this) returns the foo object but the second one inside the function returns the Window object if the foo function is used as a constructor? Shouldn't both console.log(this) return the foo object?

0 Answers
Related