樣本函數聲明函數:爲什麼函數在構造函數中聲明時不使用new關鍵字?
function Rectangle(height, width) {
this.height = height;
this.width = width;
this.calcArea = function() {
return this.height * this.width;
};
// put our perimeter function here!
this.calcPerimeter = function() {
return 2 * this.height + 2 * this.width;
};
樣品新的函數聲明:
var actions = new function() {
console.log("this is to do something");
}
爲什麼我們使用new關鍵字,同時宣佈了新的功能,但同時在構造函數中聲明它不使用new關鍵字? ?
'行動'沒有在這裏聲明爲一個函數。 – Bergi
'new'關鍵詞沒有達到你認爲的那樣。 – Pointy
你在哪裏看到'var actions = new function(){...}'? –