[COLOR=000000]If you mess around with JavaScript and forms a lot, or even just a little, you might come across needing to use the [COLOR=aa0000]
[/color] bit of code to create new options for a select box. I've noticed with this constructor a very strange thing: It's an object.
[COLOR=aa0000]
[/color]
The above code will tell you that it's an "object" and not a "function". The following code will give an error:
[COLOR=aa0000]
[/color]
That's because Option is not a function, and accessing it as if it were a function is not allowed in JavaScript. But then, the following code does not give an error:[COLOR=aa0000]
[/color]
Strangely enough, [COLOR=aa0000]
[/color] is a constructor that is not a function. It can be called correctly with the [COLOR=aa0000]
[/color] keyword but it cannot be called as a normal function. How did that happen, and how do I make my own like it?
Best regards[/color]
Code:
new Option()
[COLOR=aa0000]
Code:
alert(typeof Option);
The above code will tell you that it's an "object" and not a "function". The following code will give an error:
[COLOR=aa0000]
Code:
alert(typeof Option());
That's because Option is not a function, and accessing it as if it were a function is not allowed in JavaScript. But then, the following code does not give an error:[COLOR=aa0000]
Code:
alert(typeof new Option());
Strangely enough, [COLOR=aa0000]
Code:
Option
Code:
new
Best regards[/color]
Code:
- UNIMENT