在doc ready上获取“Uncaught TypeError:undefined不是函数”

时间:2012-12-04 17:47:53

标签: jquery twitter-bootstrap requirejs

我正在尝试将bootstrap.js添加到我的require配置中。每次~20次刷新左右,我在第23行收到Uncaught TypeError: undefined is not a function错误,这是我的文档准备好了:$(function () {

我读了this fix,这导致我在下面设置了require.config。

require.config({
  paths: {
    jquery: 'libs/jquery/jquery-min',
    underscore: 'libs/underscore/underscore-min',
    backbone: 'libs/backbone/backbone-min',
    templates: '../templates',
    bootstrap: 'libs/bootstrap/bootstrap'
  },
  shim: {
      backbone: {
          deps: ['underscore', 'jquery'],
          exports: 'Backbone'
      },
      underscore: {
          exports: '_'
      },
      bootstrap: {
          deps: ['jquery'],
          exports: "$.fn.popover"
      },
      enforceDefine: true
  }

});

require([
  'ripple',    
], function(Ripple){
    Ripple.initialize();
});

ripple.js

// Filename: ripple.js
define([
  'jquery',
  'underscore',
  'backbone',
  'router', // Request router.js
  'bootstrap'
], function ($, _, Backbone, Router, Bootstrap) {
    var initialize = function () {
        // Pass in our Router module and call it's initialize function
        Router.initialize();
    }

    return {
        initialize: initialize
    };
});

我认为这是一种竞争条件,引导偶尔会失败。有什么想法吗?

0 个答案:

没有答案