元素和函数用逗号分隔

时间:2014-01-07 18:52:19

标签: javascript syntax

这种语法意味着什么?

var _t = this, _resetProperties, _add_html5_events, _remove_html5_events, _stop_html5_timer, _start_html5_timer, _attachOnPosition, _onplay_called = false, _onPositionItems = [], _onPositionFired = 0, _detachOnPosition, _applyFromTo, _lastURL = null, _lastHTML5State;

1 个答案:

答案 0 :(得分:2)

它只是一堆变量声明/初始化,用逗号分隔。它与:

相同
var _t = this;
var _resetProperties;
var _add_html5_events;
var _remove_html5_events;
var _stop_html5_timer;
var _start_html5_timer;
var _attachOnPosition;
var _onplay_called = false;
var _onPositionItems = [];
var _onPositionFired = 0;
var _detachOnPosition;
var _applyFromTo;
var _lastURL = null;
var _lastHTML5State;

我不喜欢将初始化与这样的声明混合在一起。它很乱,不太可读。如果有的话,请对您的声明进行分组(没有值),并且仅在它们相关时进行组初始化。它不会在功能上改变代码,只会使它变得更小(在案例中更难阅读)。