码迷,mamicode.com
首页 > Web开发 > 详细

js里面如何才能让成员方法去调用类中其他成员

时间:2017-09-25 15:18:59      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:nbsp   调用   ffffff   weight   uri   imp   tom   cti   pad   

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的指向
}
}
//希望能帮到你

js里面如何才能让成员方法去调用类中其他成员

标签:nbsp   调用   ffffff   weight   uri   imp   tom   cti   pad   

原文地址:http://www.cnblogs.com/wxmdevelop/p/7591894.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!