1 year ago

#384162

test-img

Edward Sun

Why `a` can be printed from `baz`?

const Foo = function(a){

  // bar doesn't belong to any instance
  function bar(){
    console.log(a);
  };

  this.baz = function(){
    console.log(a);
  }
}

const f = new Foo(7);
f.baz() // print 7

Hi stackoverflows, can someone explain to me why f.baz() can print the a ?? Having difficulty explaining this to someone else right now

javascript

this

0 Answers

Your Answer

Accepted video resources