和Java狼狈为奸 2016-09-28 03:34 采纳率: 50%
浏览 1040
已采纳

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();
}

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

  • 写回答

3条回答

  • zhuwei_clark 2016-09-28 03:53
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题