我想编写这种接受各种数量参数的函数,如下所示:
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
我的问题是如何编写函数本身?我会尝试这样的事情,但我认为它不会工作。如何正确编写它以便函数可以接收多个参数?
var PopupBox = {
init :function (width,height) {
if (height == null) {
height=100px;
}
if (width == null) {
height=100px;
}
}
}