什么是bootstrap main.js和plugins.js脚本?

时间:2013-09-28 13:02:49

标签: javascript jquery html twitter-bootstrap

Plugins.js和main.js包含在initializrstwitter bootstrap 3中(也可能在vanilla bootstrap 3中,我还没有检查过)。我不知道他们在那里是什么,找不到getbootstrap.com的任何解释,文件本身也没有很多解释性的评论。

任何人都可以解释他们在那里做什么,他们应该做什么?对我来说,看起来像plugins.js是要加载你想要包含的任何其他JavaScript。是对的吗?你为什么这样做?


这些是plugins.js的内容(main.js为空):

// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

// Place any jQuery/helper plugins in here.

1 个答案:

答案 0 :(得分:0)

正如您所发现的,这些是HTML5 Boilerplate的一部分,而不是Bootstrap。

plugins.js文件是您可以包含所有jQuery或其他帮助程序插件的地方。

main.js文件用于主应用程序脚本,即实例化和使用插件的代码。

这些文件被H5BP构建脚本缩小并缓存。 (您会注意到主HTML模板的脚本部分对于如何引用脚本非常严格,以便在静态构建期间对其进行更新。)