See these articles for reference for the “Ext.applyIf” function and double pipes.
http://docs.sencha.com/core/manual/content/utility.html
http://homepage.ntlworld.com/kayseycarvey/controlflow4.html
Can someone explain what this logic is doing in the ExtJS framework? I want to make sure my interpretation is correct on the first line with the pipes (especially).
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;
}
Taken from ASP.NET asmx custom server proxy class:
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;
}
});
var a = b||{}a is guaranteed to be not null even if b is null or undefined. The default fall back makesa = {}(empty object).ApplyIfmethod copies properties from source to destination being careful not to overwrite any existing properties. In the following example extraParams properties are added to params properties as long as params do not have those properties defined.Ext.applyIf(params , extraParams )
The actual code is:
which adds extraParams to params object carefully avoiding any null pointer issues and make sure not to overwrite params.