样本函数声明函数:为什么函数在构造函数中声明时不使用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(){...}'? –