YepNope key value pairs not executing as expected

2019-07-12 15:19发布

问题:

I am starting to learn YepNope and have a script like such:

yepnope([
      {
        load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js',
      },
      {
        test: true,
        yep: {
          'jquery-ui' : 'js/jquery-ui.js',
          'jquery-expandable' : 'js/jquery.expandable.js',
          'triggers' : 'js/triggers.js',
          'prettify' : 'js/prettify/prettify.js'
        },

        callback: { 
          'prettify': function (url, result, key) {
              console.log(key + ' loaded ' + result);
              prettyPrint();
          }
        }

      }
     ]);

I only need a callback for prettify. However running the above displays the console log as successfully loaded, but prettyPrint() is undefined.

If I sepcify blank function callbacks for the other keys such as:

  yepnope([
      {
        load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js',
      },
      {
        test: true,
        yep: {
          'jquery-ui' : 'js/jquery-ui.js',
          'jquery-expandable' : 'js/jquery.expandable.js',
          'triggers' : 'js/triggers.js',
          'prettify' : 'js/prettify/prettify.js'
        },

        callback: { 
          'jquery-ui': function(url, result, key) {

         },
         'jquery-expandable': function(url, result, key) {

         },
        'triggers': function (url, result, key) {

        },
        'prettify': function (url, result, key) {
             console.log(key + ' loaded ' + result);
             prettyPrint();
        }
      }

    }
  ]);

This does work. So when using this syntax do we have to specify a key for each callback, even if we don't need a callback for a specific key? Or is this a bug in YepNope? I also can reproduce this in Modernizr.load version of the script.