javascript中的双分号语法

时间:2014-01-03 15:44:17

标签: javascript

有人能告诉我javascript中的双分号(;;)是什么意思吗?我在fullcalendar.js中看到了它们。

感谢。

以下是fullcalendar.js代码的片段(取自CDNJS):

(function($, undefined) {

;;

var defaults = {

    // display
    defaultView: 'month',
    aspectRatio: 1.35,
    header: {
        left: 'title',
        center: '',
        right: 'today prev,next'
    },
    weekends: true,
    weekNumbers: false,
    weekNumberCalculation: 'iso',
    weekNumberTitle: 'W',   
    allDayDefault: true,
    ignoreTimezone: true,

    // event ajax
    lazyFetching: true,
    startParam: 'start',
    endParam: 'end',

    // time formats
    titleFormat: {
        month: 'MMMM yyyy',
        week: "MMM d[ yyyy]{ '—'[ MMM] d yyyy}",
        day: 'dddd, MMM d, yyyy'
    },
    columnFormat: {
        month: 'ddd',
        week: 'ddd M/d',
        day: 'dddd M/d'
    },
    timeFormat: { // for event elements
        '': 'h(:mm)t' // default
    },

    // locale
    isRTL: false,
    firstDay: 0,
    monthNames: ['January','February','March','April','May','June','July','August','September','October','November','December'],
    monthNamesShort: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
    dayNames: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'],
    dayNamesShort: ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
    buttonText: {
        prev: "<span class='fc-text-arrow'>&lsaquo;</span>",
        next: "<span class='fc-text-arrow'>&rsaquo;</span>",
        prevYear: "<span class='fc-text-arrow'>&laquo;</span>",
        nextYear: "<span class='fc-text-arrow'>&raquo;</span>",
        today: 'today',
        month: 'month',
        week: 'week',
        day: 'day'
    },

    // jquery-ui theming
    theme: false,
    buttonIcons: {
        prev: 'circle-triangle-w',
        next: 'circle-triangle-e'
    },

    //selectable: false,
    unselectAuto: true,

    dropAccept: '*',

    handleWindowResize: true

};

...
}

2 个答案:

答案 0 :(得分:10)

The double semicolons ;; has nothing to do with a for loop in the case of fullcalendar.js (which is now on github).

There is no value to the parsing or execution of the code itself (it is basically innocuous); rather the author has used ;; merely as a sentinel to separate logical chunks of code. It was a weird and esoteric choice to do this, but as it turns out it is very helpful to use CTRL-F to search for ;; to jump from one section to another (for example, the class definitions appear to be separated in this way).

The author could have used comments, for example:

/* ;; */

or

/* CLASSDEF */

etc., but he didn't.

Also confirmed: the JavaScript minifiers I tested remove the ;; so definitely not critical to the code, and not helpful as a sentinel when searching minified code. (but neither are comments because they are stripped out).

答案 1 :(得分:4)

Empty “for” loop

for(;;){...}while(1){...}

相同

for(;;)while(1)

更容易跳出来表示“无限循环”

facebook's AJAX responses都以空循环开始。