次のようなさまざまな数のパラメーターを受け入れるこの種の関数を書きたいと思います。
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;
}
}
}