YepNope key value pairs not executing as expected

时间秒杀一切 提交于 2019-12-24 05:22:09

问题


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.

来源:https://stackoverflow.com/questions/9584118/yepnope-key-value-pairs-not-executing-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!