2015-11-30 54 views
0

我試圖在ES6 JavaScript的一些東西,和我有一個問題, 試圖使用功能,它GOTS錯誤內部功能..ES6類功能函數調用內部功能

 class Model { 
      constructor(properties) { 
       this.properties = properties; 
      } 

      functionA() { 
       return functionB() * 3; 
      } 
      functionB(){ 
       return 5 * 3; 
      } 
     } 

這段代碼去工作,我的意思是在functionA()中調用functionB?

+0

嘗試'this.functionB()' –

回答

1

你會問同樣的問題,如果你有以下形式寫它:

function Model(properties) { 
    this.properties = properties; 
} 

Model.prototype.functionA = function() { 
    return /*insert function B call*/ * 3; 
}; 

Model.prototype.functionB = function() { 
    return 5 * 3; 
}; 

ES6仍然是由相同的JS範圍的規則管轄,ES6類是隻爲你見上什麼syntaxic糖。

因此,您必須使用this.functionB,就像您在構造函數中那樣在新構建的Model實例上設置properties成員。

+0

以及thnx! ,它似乎是工作..可以關閉帖子.. –