在以下JavaScript代码中调用main()。 我的问题是为什么第二个构造函数被调用而不是第一个? 我在这里错过了什么?非常基本的JavaScript构造函数问题
谢谢!
function AllInputs() {
alert("cons 1");
this.radioInputs = [];
alert(this);
}
function AllInputs(radioElement) {
alert("cons 2");
this.radioInputs = [radioElement];
alert(this);
}
AllInputs.prototype.toString = function() {
return "[object AllInputs: radioInputs: " + this.radioInputs.length + "]";
}
function main() {
var result = new AllInputs();
}
感谢您的解释! – 2010-04-13 03:12:28