Possible Duplicate:
JavaScript variable number of arguments to function
JS: functions arguments default values
I want to write this sort of function that accepts various number of parameters like this:
PopupBox.init() //Creating a pop up box with a default height and width of 100px
PopupBox.init(50px) //Creating a popup with height and width of 50px
PopupBox.init(50px,100px) //Creating a popup with the height 50px and width 100px
My question is how do I write the function itself? I would have tried something like this but I assume it won't work. how do I write it correctly so the function can receive multiple parameters?
var PopupBox = {
init :function (width,height) {
if (height == null) {
height=100px;
}
if (width == null) {
height=100px;
}
}
}