Very basic Javascript constructors problem

Posted by misha-moroshko on Stack Overflow See other posts from Stack Overflow or by misha-moroshko
Published on 2010-04-13T02:44:32Z Indexed on 2010/04/13 2:52 UTC
Read the original article Hit count: 290

Filed under:
|

Hi,

In the following JavaScript code main() is called. My question is why the second constructor is called rather than the first one ? What am I missing here ?

Thanks !!

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();
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about constructor