Skip to content

Commit

Permalink
Convert var to let and const
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Aug 15, 2018
1 parent 07e83d1 commit b1c57e9
Show file tree
Hide file tree
Showing 72 changed files with 2,365 additions and 2,382 deletions.
46 changes: 23 additions & 23 deletions src/_utils/inheritance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Inspired by base2 and Prototype
(function () {

var initializing = false;
let initializing = false;

var fnTest = /xyz/.test(function () {
const fnTest = /xyz/.test(function () {
xyz;
}) ? /\b_super\b/ : /.*/;

Expand All @@ -19,30 +19,30 @@
// Create a new Class that inherits from this class
Class.extend = function (prop) {

var _super = this.prototype;
const _super = this.prototype;

// Instantiate a base class (but only create the instance,
// don't run the init constructor)
initializing = true;
var prototype = new this();
const prototype = new this();
initializing = false;

// Copy the properties over onto the new prototype
for (var name in prop) {
for (const name in prop) {

//
if (name === "_props") {
var props = prop[name];
var descriptor;
for (var key in props) {
const props = prop[name];
let descriptor;
for (const key in props) {
descriptor = props[key];
if (key.indexOf(",") >= 0) { // Aliased property name of form "foo, bar, baz": { .. }
var aliases = key.split(",");
for (var i = 0, len = aliases.length; i < len; i++) {
var alias = aliases[i].trim();
const aliases = key.split(",");
for (let i = 0, len = aliases.length; i < len; i++) {
const alias = aliases[i].trim();
if (!descriptor.set) {
(function () {
var name3 = alias;
const name3 = alias;
descriptor.set = function () {
this.warn("Property '" + name3 + "' is read-only, ignoring assignment");
};
Expand All @@ -59,7 +59,7 @@

if (!descriptor.set) {
(function () {
var name = key;
const name = key;
descriptor.set = function () {
this.warn("Property '" + name + "' is read-only, ignoring assignment");
};
Expand All @@ -74,10 +74,10 @@

// Check if we're overwriting an existing function

var existsOnSuper = !!_super[name];
var isFunc = typeof prop[name] === "function";
var superIsFunc = typeof _super[name] === "function";
var passFnTest = fnTest.test(prop[name]);
const existsOnSuper = !!_super[name];
const isFunc = typeof prop[name] === "function";
const superIsFunc = typeof _super[name] === "function";
const passFnTest = fnTest.test(prop[name]);

if (existsOnSuper) {
if (isFunc && !superIsFunc) {
Expand All @@ -97,15 +97,15 @@

prototype[name] = (function (name, fn) {
return function () {
var tmp = this._super;
const tmp = this._super;

// Add a new ._super() method that is the same method
// but on the super-class
this._super = _super[name];

// The method only need to be bound temporarily, so we
// remove it when we're done executing
var ret = fn.apply(this, arguments);
const ret = fn.apply(this, arguments);
this._super = tmp;

return ret;
Expand Down Expand Up @@ -166,11 +166,11 @@
*/
var createUUID = (function () {
// http://www.broofa.com/Tools/Math.uuid.htm
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
var uuid = new Array(36);
var rnd = 0, r;
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
const uuid = new Array(36);
let rnd = 0, r;
return function () {
for (var i = 0; i < 36; i++) {
for (let i = 0; i < 36; i++) {
if (i === 8 || i === 13 || i === 18 || i === 23) {
uuid[i] = '-';
} else if (i === 14) {
Expand Down
10 changes: 5 additions & 5 deletions src/_utils/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ xeogl.utils.Map = function (items, baseId) {
this.items = items || [];

baseId = baseId || 0;
var lastUniqueId = baseId + 1;
let lastUniqueId = baseId + 1;

/**
* Usage:
Expand All @@ -18,9 +18,9 @@ xeogl.utils.Map = function (items, baseId) {
* id = myMap.addItem("foo", "bar") // ID is "foo"
*/
this.addItem = function () {
var item;
let item;
if (arguments.length === 2) {
var id = arguments[0];
const id = arguments[0];
item = arguments[1];
if (this.items[id]) { // Won't happen if given ID is string
throw "ID clash: '" + id + "'";
Expand All @@ -31,7 +31,7 @@ xeogl.utils.Map = function (items, baseId) {
} else {
item = arguments[0] || {};
while (true) {
var findId = lastUniqueId++;
const findId = lastUniqueId++;
if (!this.items[findId]) {
this.items[findId] = item;
return findId;
Expand All @@ -41,7 +41,7 @@ xeogl.utils.Map = function (items, baseId) {
};

this.removeItem = function (id) {
var item = this.items[id];
const item = this.items[id];
delete this.items[id];
return item;
};
Expand Down
80 changes: 40 additions & 40 deletions src/animation/cameraFlightAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@

"use strict";

var math = xeogl.math;
const math = xeogl.math;

xeogl.CameraFlightAnimation = xeogl.Component.extend({

Expand Down Expand Up @@ -201,7 +201,7 @@
*/
flyTo: (function () {

var tempVec3 = math.vec3();
const tempVec3 = math.vec3();

return function (params, callback, scope) {

Expand All @@ -216,7 +216,7 @@
this._callback = callback;
this._callbackScope = scope;

var camera = this.scene.camera;
const camera = this.scene.camera;

this._eye1[0] = camera.eye[0];
this._eye1[1] = camera.eye[1];
Expand All @@ -233,11 +233,11 @@
this._orthoScale1 = camera.ortho.scale;
this._orthoScale2 = params.orthoScale || this._orthoScale1;

var aabb;
var eye;
var look;
var up;
var componentId;
let aabb;
let eye;
let look;
let up;
let componentId;

if (params.aabb) {
aabb = params.aabb;
Expand All @@ -260,7 +260,7 @@

// Argument must be an instance or ID of a Component (subtype)

var component = params;
let component = params;

if (xeogl._isNumeric(component) || xeogl._isString(component)) {

Expand All @@ -284,7 +284,7 @@
aabb = component.aabb || this.scene.aabb;
}

var poi = params.poi;
const poi = params.poi;

if (aabb) {

Expand All @@ -310,14 +310,14 @@

aabb = aabb.slice();

var aabbCenter = math.getAABB3Center(aabb);
const aabbCenter = math.getAABB3Center(aabb);
this._look2 = poi || aabbCenter;

var eyeLookVec = math.subVec3(this._eye1, this._look1, tempVec3);
var eyeLookVecNorm = math.normalizeVec3(eyeLookVec);
var diag = poi ? math.getAABB3DiagPoint(aabb, poi) : math.getAABB3Diag(aabb);
var fitFOV = params.fitFOV || this._fitFOV;
var sca = Math.abs(diag / Math.tan(fitFOV * xeogl.math.DEGTORAD));
const eyeLookVec = math.subVec3(this._eye1, this._look1, tempVec3);
const eyeLookVecNorm = math.normalizeVec3(eyeLookVec);
const diag = poi ? math.getAABB3DiagPoint(aabb, poi) : math.getAABB3Diag(aabb);
const fitFOV = params.fitFOV || this._fitFOV;
const sca = Math.abs(diag / Math.tan(fitFOV * xeogl.math.DEGTORAD));

this._orthoScale2 = diag * 1.1;

Expand Down Expand Up @@ -390,30 +390,30 @@
* @param [params.fit] {Boolean} Whether to fit the target to the view volume. Overrides {{#crossLink "CameraFlightAnimation/fit:property"}}{{/crossLink}}.
*/
jumpTo: function (params) {
var self = this;
const self = this;
// xeogl.scheduleTask(function () { // Ensures that required asynch boundaries are built first
self._jumpTo(params);
// });
},

_jumpTo: (function () {

var newEye = math.vec3();
var newLook = math.vec3();
var newUp = math.vec3();
var newLookEyeVec = math.vec3();
var tempVec3e = math.vec3();
let newEye = math.vec3();
let newLook = math.vec3();
let newUp = math.vec3();
const newLookEyeVec = math.vec3();
const tempVec3e = math.vec3();

return function (params) {

if (this._flying) {
this.stop();
}

var camera = this.scene.camera;
const camera = this.scene.camera;

var aabb;
var componentId;
let aabb;
let componentId;

if (params.aabb) { // Boundary3D

Expand All @@ -433,7 +433,7 @@

// Argument must be an instance or ID of a Component (subtype)

var component = params;
let component = params;

if (xeogl._isNumeric(component) || xeogl._isString(component)) {

Expand All @@ -450,7 +450,7 @@
aabb = component.aabb || this.scene.aabb;
}

var poi = params.poi;
const poi = params.poi;

if (aabb) {

Expand All @@ -473,9 +473,9 @@

math.normalizeVec3(newLookEyeVec);

var dist;
let dist;

var fit = (params.fit !== undefined) ? params.fit : this._fit;
const fit = (params.fit !== undefined) ? params.fit : this._fit;
if (fit) {
dist = Math.abs((diag) / Math.tan((params.fitFOV || this._fitFOV) * xeogl.math.DEGTORAD));

Expand Down Expand Up @@ -507,31 +507,31 @@

_update: (function () {

var newLookEyeVec = math.vec3();
var newEye = math.vec3();
var newLook = math.vec3();
var newUp = math.vec3();
var lookEyeVec = math.vec3();
const newLookEyeVec = math.vec3();
const newEye = math.vec3();
const newLook = math.vec3();
const newUp = math.vec3();
const lookEyeVec = math.vec3();

return function () {

if (!this._flying) {
return;
}

var time = Date.now();
const time = Date.now();

var t = (time - this._time1) / (this._time2 - this._time1);
let t = (time - this._time1) / (this._time2 - this._time1);

var stopping = (t >= 1);
const stopping = (t >= 1);

if (t > 1) {
t = 1;
}

t = this.easing ? this._ease(t, 0, 1, 1) : t;

var camera = this.scene.camera;
const camera = this.scene.camera;


if (this._flyingEye || this._flyingLook) {
Expand All @@ -556,7 +556,7 @@

math.lerpVec3(t, 0, 1, this._look1, this._look2, newLook);

var dist;
let dist;

if (this._trail) {
math.subVec3(newLook, camera.look, newLookEyeVec);
Expand Down Expand Up @@ -611,7 +611,7 @@
this._time1 = null;
this._time2 = null;

var callback = this._callback;
const callback = this._callback;

if (callback) {

Expand Down
Loading

0 comments on commit b1c57e9

Please sign in to comment.