OOJS调用其他方法

时间:2014-11-21 21:20:14

标签: javascript oop

var Lines = function(startXCon, endXCon,startYCon, endYCon)
{


    this.drawCurve = function()
    {


    }
    this.changeCurve = function(e)
    {
        //how can I call drawCurve from this method
    }

}

我的代码中的注释解释了这个问题。这是可能的还是所有方法都是私有的?

1 个答案:

答案 0 :(得分:0)

像这样:

var Lines = function(startXCon, endXCon,startYCon, endYCon){   
  var self = this; // store this as a variable to use in nested function
  this.drawCurve = function(){}
  this.changeCurve = function(e){
   self.drawCurve(); //now call this.drawCurve()
  }
}