App.BookStore = function(config) {
var config = config || {};            //我很想知道这种写法是什么意思
Ext.applyIf(config, {
reader: new Ext.data.XmlReader({
           // records will have an "Item" tag
           record: 'Item',
           id: 'ASIN',
           totalRecords: '@total'
       }, [
           // set up the fields mapping into the xml doc
           // The first needs mapping, the others are very basic
           {name: 'Author', mapping: 'ItemAttributes > Author'},
           'Title',
   'Manufacturer',
   'ProductGroup',
   // Detail URL is not part of the column model of the grid
   'DetailPageURL'
       ])
});
// call the superclass's constructor
App.BookStore.superclass.constructor.call(this, config);
};

解决方案 »

  1.   


    var config = config || {}; //我很想知道这种写法是什么意思中间的||是或的意思,这样的写法等同于 if !config {config={}}
    即取这两个值中不为空的那一个(准确点说是为真的那一个,因为在js里,空值代表false,有值的变量在判断时可以做为true)
      

  2.   

    var config = undefined;alert(config.a); // 抛异常。因为config为undefined安全的写法是
    if (config) alert(config.a);---------var config = undefined;config = config || {};
    config.a // 打印undefined,这样保证config至少能访问属性,省去判断,否则每一个属性你都要判断config是否可以访问。
      

  3.   

    在一个js文件中这样写到:   (function(){省略中间代码部分……}).()  这种写法是什么呢?
      

  4.   

    var config = config || {};|| 他是或者
    你可以理解成执行顺序, 如果 || 符号之前执行结果为 0、假、null、undefined、空字符 时继续执行 || 之后的代码
    直到某次执行不获得这些值,那么返回这个值
    <script type="text/javascript" >
    function f(v){
    alert(v)
    if ( v === 2 ) return true
    return false
    }
    var a = f(1) || f(2) ||  f(3) ||  f(4)
    </script>
      

  5.   


    正解|| 运算符特性,高效!当config= 0 null false undefined
    时,设置为一个 对象 {}
      

  6.   

    (function(){省略中间代码部分……}).() 这种写法让你写的这个函数直接执行