Better variables scoping

This commit is contained in:
Frederic Junod
2018-05-14 14:28:31 +02:00
parent 7f0043694d
commit 9f3b103bbf
4 changed files with 15 additions and 24 deletions

View File

@@ -115,8 +115,7 @@ Collection.prototype.clear = function() {
* @api
*/
Collection.prototype.extend = function(arr) {
let i, ii;
for (i = 0, ii = arr.length; i < ii; ++i) {
for (let i = 0, ii = arr.length; i < ii; ++i) {
this.push(arr[i]);
}
return this;
@@ -225,8 +224,7 @@ Collection.prototype.push = function(elem) {
*/
Collection.prototype.remove = function(elem) {
const arr = this.array_;
let i, ii;
for (i = 0, ii = arr.length; i < ii; ++i) {
for (let i = 0, ii = arr.length; i < ii; ++i) {
if (arr[i] === elem) {
return this.removeAt(i);
}
@@ -270,8 +268,7 @@ Collection.prototype.setAt = function(index, elem) {
this.dispatchEvent(
new CollectionEvent(CollectionEventType.ADD, elem));
} else {
let j;
for (j = n; j < index; ++j) {
for (let j = n; j < index; ++j) {
this.insertAt(j, undefined);
}
this.insertAt(index, elem);

View File

@@ -172,9 +172,8 @@ PointerEventHandler.prototype.registerSource = function(name, source) {
*/
PointerEventHandler.prototype.register_ = function() {
const l = this.eventSourceList_.length;
let eventSource;
for (let i = 0; i < l; i++) {
eventSource = this.eventSourceList_[i];
const eventSource = this.eventSourceList_[i];
this.addEvents_(eventSource.getEvents());
}
};
@@ -186,9 +185,8 @@ PointerEventHandler.prototype.register_ = function() {
*/
PointerEventHandler.prototype.unregister_ = function() {
const l = this.eventSourceList_.length;
let eventSource;
for (let i = 0; i < l; i++) {
eventSource = this.eventSourceList_[i];
const eventSource = this.eventSourceList_[i];
this.removeEvents_(eventSource.getEvents());
}
};

View File

@@ -219,9 +219,8 @@ TouchSource.prototype.processTouches_ = function(inEvent, inFunction) {
function preventDefault() {
inEvent.preventDefault();
}
let i, pointer;
for (i = 0; i < count; ++i) {
pointer = this.touchToPointer_(inEvent, touches[i]);
for (let i = 0; i < count; ++i) {
const pointer = this.touchToPointer_(inEvent, touches[i]);
// forward touch preventDefaults
pointer.preventDefault = preventDefault;
inFunction.call(this, inEvent, pointer);
@@ -237,9 +236,8 @@ TouchSource.prototype.processTouches_ = function(inEvent, inFunction) {
*/
TouchSource.prototype.findTouch_ = function(touchList, searchId) {
const l = touchList.length;
let touch;
for (let i = 0; i < l; i++) {
touch = touchList[i];
const touch = touchList[i];
if (touch.identifier === searchId) {
return true;
}
@@ -267,10 +265,9 @@ TouchSource.prototype.vacuumTouches_ = function(inEvent) {
const count = keys.length;
if (count >= touchList.length) {
const d = [];
let i, key, value;
for (i = 0; i < count; ++i) {
key = keys[i];
value = this.pointerMap[key];
for (let i = 0; i < count; ++i) {
const key = keys[i];
const value = this.pointerMap[key];
// Never remove pointerId == 1, which is mouse.
// Touch identifiers are 2 smaller than their pointerId, which is the
// index in pointermap.
@@ -279,7 +276,7 @@ TouchSource.prototype.vacuumTouches_ = function(inEvent) {
d.push(value.out);
}
}
for (i = 0; i < d.length; ++i) {
for (let i = 0; i < d.length; ++i) {
this.cancelOut_(inEvent, d[i]);
}
}

View File

@@ -317,12 +317,11 @@ export function createTransformFromCoordinateTransform(coordTransform) {
const length = input.length;
const dimension = opt_dimension !== undefined ? opt_dimension : 2;
const output = opt_output !== undefined ? opt_output : new Array(length);
let point, i, j;
for (i = 0; i < length; i += dimension) {
point = coordTransform([input[i], input[i + 1]]);
for (let i = 0; i < length; i += dimension) {
const point = coordTransform([input[i], input[i + 1]]);
output[i] = point[0];
output[i + 1] = point[1];
for (j = dimension - 1; j >= 2; --j) {
for (let j = dimension - 1; j >= 2; --j) {
output[i + j] = input[i + j];
}
}