Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ExtJS4:applyIf在ExtJS代码中使用两个管道做什么?_Javascript_Extjs_Proxy - Fatal编程技术网

Javascript ExtJS4:applyIf在ExtJS代码中使用两个管道做什么?

Javascript ExtJS4:applyIf在ExtJS代码中使用两个管道做什么?,javascript,extjs,proxy,Javascript,Extjs,Proxy,有关“Ext.applyIf”函数和双管道的参考,请参阅这些文章 有人能解释一下这个逻辑在ExtJS框架中的作用吗?我想确保我对管道第一行的解释是正确的(尤其是) 取自ASP.NET asmx自定义服务器代理类: Ext.define('Ext.ux.AspWebAjaxProxy', { extend: 'Ext.data.proxy.Ajax', require: 'Ext.data', buildRequest: function (operation) {

有关“Ext.applyIf”函数和双管道的参考,请参阅这些文章

有人能解释一下这个逻辑在ExtJS框架中的作用吗?我想确保我对管道第一行的解释是正确的(尤其是)

取自ASP.NET asmx自定义服务器代理类:

Ext.define('Ext.ux.AspWebAjaxProxy', {
    extend: 'Ext.data.proxy.Ajax',
    require: 'Ext.data',

    buildRequest: function (operation) {
        var params = Ext.applyIf(operation.params || {}, this.extraParams || {}), request;
        params = Ext.applyIf(params, this.getParams(params, operation));
        if (operation.id && !params.id) {
            params.id = operation.id;
        }

        params = Ext.JSON.encode(params);

        request = Ext.create('Ext.data.Request', {
            params: params,
            action: operation.action,
            records: operation.records,
            operation: operation,
            url: operation.url
        });
        request.url = this.buildUrl(request);
        operation.request = request;
        return request;
    }
});
考虑:

function foo(cfg) {
    cfg = cfg || {};
    console.log(cfg.x);
}

foo({x: 1});
foo();
因此,本质上,我们是说,如果传递给方法的cfg是“falsy”(read、undefined或null),那么将其设置为空对象,以便在读取“x”属性时不会出现引用错误。

请考虑:

function foo(cfg) {
    cfg = cfg || {};
    console.log(cfg.x);
}

foo({x: 1});
foo();
所以本质上,我们是说,如果传递给方法的cfg是“falsy”(read、undefined或null),那么将其设置为空对象,以便在读取“x”属性时不会出现引用错误

  • 双管道是一种javascript技巧,用于指定默认值。正如Evan所说,它经常用于避免空指针问题。在
    var的示例中,a=b |{}
    a保证不为null,即使b为null或未定义。默认的回退使
    a={}
    (空对象)
  • ApplyIf
    方法将属性从源复制到目标,注意不要覆盖任何现有属性。在下面的示例中,只要参数没有定义这些属性,就会将extraParams属性添加到params属性中

    Ext.applyIf(参数,外参数)

  • 实际代码为:

    Ext.applyIf(operation.params || {}, this.extraParams || {}),
    
    它将extraParams添加到params对象中,小心避免任何空指针问题,并确保不覆盖params

  • 双管道是一种javascript技巧,用于指定默认值。正如Evan所说,它经常用于避免空指针问题。在
    var的示例中,a=b |{}
    a保证不为null,即使b为null或未定义。默认的回退使
    a={}
    (空对象)
  • ApplyIf
    方法将属性从源复制到目标,注意不要覆盖任何现有属性。在下面的示例中,只要参数没有定义这些属性,就会将extraParams属性添加到params属性中

    Ext.applyIf(参数,外参数)

  • 实际代码为:

    Ext.applyIf(operation.params || {}, this.extraParams || {}),
    
    它将extraParams添加到params对象中,小心避免任何空指针问题,并确保不覆盖params