2013-06-20 17 views
0
! function (d, b, c, a) { 
    Velop.AssignmentQuestionAnswerHandler = function (e) { 
     this.__construct(e) 
    }; 
    Velop.AssignmentQuestionAnswerHandler.prototype = { 
     __construct: function (e) { 
      this.clientAction = Velop.resolveClientAction("client", true); 
      this.sectionIdAction = XenForo.getAction("section"); 
      this.$input = e; 
      this.assignmentQuestionControl = e.closest(".AssignmentQuestionAnswerHandler"); 
      this.$input.change(d.context(this, "save")); 
      this.lastValue = null 
     }, 
... 

我在js文件中看到了上面的腳本。在js文件中__construct的問題

問題:

這條線是什麼意思? __construct: function (e)?這是否等於constructor: function (e)?我在php文件中看到了__construct,但我從未看到它用於js文件。

+4

'__construct'有在Javascript中沒有特殊的含義,有人乾脆選擇了這個名字。 – deceze

+0

JavaScript中沒有構造函數的概念。它只是一個使用下劃線的函數聲明。 – skparwal

回答

2

我的猜測是,它只是一個內部約定,將邏輯與實際的構造函數分開,並且可以在需要時將其作爲方法調用。其他庫例如使用_init

function Class(e) { 
    this.__construct(e); 
} 

__construct本身在JavaScript中沒有意義。另外,它是在一個對象中,可以命名任何你想要的鍵。

0

這似乎是一些(奇怪的)類構造函數。通過這個.__構造,可以從函數外部訪問構造函數。

normaly你標記內部功能用下劃線... :)