JavaScript函数参数问题,大神求指点。

公司别人写的代码:

 function XMLHttpRequestCaller(_caller, serviceName, methodName, async, method, needCheckLogin, actionUrl) {
    if((!serviceName || !methodName) && !actionUrl){
        alert("AJAX Service name or method, actionUrl is not null.");
        throw new Error(3, "AJAX Service name or method is not null.");
    }

    this.params = new AjaxParameter();
    this.serviceName = serviceName;
    this.methodName = methodName;
    this.needCheckLogin = needCheckLogin == null ? "true" : needCheckLogin;
    this.returnValueType = "XML"; //XML TEXT

    this.method = method || AJAX_XMLHttpRequest_DEFAULT_METHOD;
    this.async = (async == null ? AJAX_XMLHttpRequest_DEFAULT_async : async);
    this._caller = _caller;
    this.actionUrl = actionUrl;

    this.filterLogoutMessage = true;
    this.closeConnection = false;
};

这个类有7个参数,但在用到的地方调用这个类时,他们却只写了4个参数,为什么这样能行得通,我是学Java的,Java中是不可以,所以我不能理解。

 function savePrintCount() {
    var requestCaller = new XMLHttpRequestCaller(this, "czxzfManager", "save", false);
    requestCaller.addParameter(1, "String", summaryId);
    requestCaller.serviceRequest();
}

求大神指点,为什么参数不完整也能正常

这不是函数,是对象,通过构造函数定义出来的对象。对于对象,你可以使用4个参数构造,也可以使用7个参数构造

可以这样使用,只写4个会将这4个传递给函数的前四个值,后3个使用默认值。

你不写参数名称都行,使用arguments对象就可以获取。写参数名称没传递时就是undefined这个值

javascript函数参数arguments,callee,caller