What happens with “var” variables inside a JavaScript Constructor?

后端 未结 7 1035
忘掉有多难
忘掉有多难 2020-12-24 14:49

example:

function Foo() {
    this.bla = 1;
    var blabla = 10;
    blablabla = 100;
    this.getBlabla = function () { 
        return blabla; // exposes b         


        
7条回答
  •  隐瞒了意图╮
    2020-12-24 14:54

    That variable is local to the constructor and won't be accessible outside of that scope (be it through this or otherwise), unless it is captured by a closure.

提交回复
热议问题