JavaScript this

87 阅读1分钟

举个例子解释

function Base(){
    this.avalue = 11;
    this.bfunc=function(){
        this.bvalue = 12;
    }
}
var b = new Base();
b.avalue;
b.bfunc();
  • b.value的流程为包含this的函数是否用new调用-->this.value的this指向b
  • b.func()的流程为包含this的函数是否用new调用-->包含this的函数是否用.调用-->this.bvalue的this指向b