function fun(){
var _this = this;
//如果函数是用var定义的私有函数,如下
var func1 = function(){ }
//那么类中其他函数都可以直接通过func1()的形式调用
//如果函数是共有的,即用this定义,如下
this.func2 = function(){ }
/*则需要得到func对像的引用,即fun中的this(注意:是fun中的).
    然而到了调用者函数(如下的caller)内部时,this指的是caller函数而不再是fun,所以可以考虑在fun中定义一个私有变量 var _this = this 来保证指向的是fun
*/
//例子:在this.caller中调用类中的其他函数
this.caller = function(){
    func1();//私有函数直接调用
    _this.func2();//公共函数,需要fun的this的指向
}
}
//希望能帮到你

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2021-06-15
  • 2022-12-23
  • 2022-02-19
  • 2021-12-26
  • 2022-12-23
猜你喜欢
  • 2021-06-09
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2021-07-30
  • 2022-12-23
相关资源
相似解决方案