let
or const
instead of var
JS-0239 868 }
869
870 if (this.colorMode !== ColorMode.Feed) {
871 var extruder = Number(tokenString.substring(1)) % this.extruderCount; 872 if (extruder < 0) extruder = 0;
873 this.currentColor = this.tools[extruder]?.color?.clone() ?? new Color3(1, 0, 0);
874 }
929
930 chunk(arr, chunkSize) {
931 var R = [];
932 for (var i = 0, len = arr.length; i < len; i += chunkSize) R.push(arr.slice(i, i + chunkSize)); 933 return R;
934 }
935
928 }
929
930 chunk(arr, chunkSize) {
931 var R = []; 932 for (var i = 0, len = arr.length; i < len; i += chunkSize) R.push(arr.slice(i, i + chunkSize));
933 return R;
934 }
626 return;
627 }
628
629 var lines = file.split('\n'); 630
631 //Extract metadata from slicer to set render settings
632 this.slicer.processComments(lines, this);
24 var dynamicTexture = new DynamicTexture('DynamicTexture', 50, this.scene, true);
25 dynamicTexture.hasAlpha = true;
26 dynamicTexture.drawText(text, 5, 40, 'bold 36px Arial', color, 'transparent', true);
27 var plane = Mesh.CreatePlane('TextPlane', size, this.scene, true); 28 plane.material = new StandardMaterial('TextPlaneMaterial', this.scene);
29 plane.material.backFaceCulling = false;
30 plane.material.specularColor = new Color3(0, 0, 0);
It is recommended to use let
or const
over var
.
This will help prevent re-declaration of variables that are in the global scope when using var
.
ES6 allows programmers to create variables with block scope instead of function scope using the let
and const
keywords.
Block scope is common in many other programming languages and helps programmers avoid mistakes such as this one:
var count = people.length;
var enoughFood = count > sandwiches.length;
if (enoughFood) {
var count = sandwiches.length; // accidentally overriding the count variable
console.log("We have " + count + " sandwiches for everyone. Plenty for all!");
}
// our count variable is no longer accurate
console.log("We have " + count + " people and " + sandwiches.length + " sandwiches!");
Block scoped variables shadow outer declarations instead of writing to them.
NOTE: There are certain edge cases where users might want to consider var. Consider this example:
var lib = lib || { run: () => {} }
Here, lib
might be a library that is exposed to an HTML file using a <script>
tag.
The var
keyword helps avoid re-writing lib
if it has already been declared via an injected script that was executed before this one.
Ideally, you should let bundlers worry about cases like this.
But if you want to use var
anyway, consider using a skipcq comment, or disabling the issue altogether.
var x = "y";
var CONFIG = {};
let x = "y";
const CONFIG = {};