Skip to content

Commit

Permalink
Merge pull request #10050 from CesiumGS/let-const-code-examples
Browse files Browse the repository at this point in the history
Update documentation examples to use const/let
  • Loading branch information
sanjeetsuhag committed Jan 28, 2022
2 parents 9855a6d + 1edbc26 commit 63340e3
Show file tree
Hide file tree
Showing 215 changed files with 940 additions and 940 deletions.
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Custom DataSource.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* will be derived from the url.
*
* @example
* var dataSource = new Cesium.WebGLGlobeDataSource();
* const dataSource = new Cesium.WebGLGlobeDataSource();
* dataSource.loadUrl('sample.json');
* viewer.dataSources.add(dataSource);
*/
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Contributors/BuildGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ It is possible to configure your `travis.yml` and `gulpfile.cjs` to deploy to a
- In `gulpfile.cjs`, edit the following line:

```
var travisDeployUrl = "http://cesium-dev.s3-website-us-east-1.amazonaws.com/cesium/";
const travisDeployUrl = "http://cesium-dev.s3-website-us-east-1.amazonaws.com/cesium/";
```

- Edit the URL to match the URL of the S3 bucket specified in `travis.yml`
Expand Down
14 changes: 7 additions & 7 deletions Documentation/Contributors/DocumentationGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Useful examples:
* ...
*
* @example
* var n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0
* const n = Cesium.Math.lerp(0.0, 2.0, 0.5); // returns 1.0
*/
CesiumMath.lerp = function(p, q, time) {
// ...
Expand All @@ -205,7 +205,7 @@ CesiumMath.lerp = function(p, q, time) {
*
* @example
* // Apply non-uniform scale to node LOD3sp
* var node = model.getNode('LOD3sp');
* const node = model.getNode('LOD3sp');
* node.matrix = Cesium.Matrix4.fromScale(new Cesium.Cartesian3(5.0, 1.0, 1.0), node.matrix);
*/
Model.prototype.getNode = function(name) {
Expand All @@ -219,7 +219,7 @@ Unnecessary example:
* ..
*
* @example
* var f = Cesium.Math.EPSILON1;
* const f = Cesium.Math.EPSILON1;
*/
CesiumMath.EPSILON1 = 0.1;
```
Expand Down Expand Up @@ -364,12 +364,12 @@ Cartesian3.ZERO = Object.freeze(new Cartesian3(0.0, 0.0, 0.0));
*
* @example
* // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0)
* var v = [1.0, 2.0, 3.0, 4.0];
* var p = Cesium.Cartesian4.fromArray(v);
* const v = [1.0, 2.0, 3.0, 4.0];
* const p = Cesium.Cartesian4.fromArray(v);
*
* // Create a Cartesian4 with (1.0, 2.0, 3.0, 4.0) using an offset into an array
* var v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
* var p2 = Cesium.Cartesian4.fromArray(v2, 2);
* const v2 = [0.0, 0.0, 1.0, 2.0, 3.0, 4.0];
* const p2 = Cesium.Cartesian4.fromArray(v2, 2);
*/
Cartesian4.fromArray = Cartesian4.unpack;
```
Expand Down
50 changes: 25 additions & 25 deletions Documentation/Contributors/TestingGuide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ import { Cartesian3 } from "../../Source/Cesium.js";

describe("Cartesian3", function () {
it("construct with default values", function () {
var cartesian = new Cartesian3();
const cartesian = new Cartesian3();
expect(cartesian.x).toEqual(0.0);
expect(cartesian.y).toEqual(0.0);
expect(cartesian.z).toEqual(0.0);
Expand All @@ -262,8 +262,8 @@ We often can't rely on an exact floating-point comparison. In this case, use `to

```javascript
it("angleBetween works for acute angles", function () {
var x = new Cartesian3(0.0, 1.0, 0.0);
var y = new Cartesian3(1.0, 1.0, 0.0);
const x = new Cartesian3(0.0, 1.0, 0.0);
const y = new Cartesian3(1.0, 1.0, 0.0);
expect(Cartesian3.angleBetween(x, y)).toEqualEpsilon(
CesiumMath.PI_OVER_FOUR,
CesiumMath.EPSILON14
Expand Down Expand Up @@ -311,7 +311,7 @@ it("fromDegrees throws with no latitude", function () {
The Jasmine functions `beforeAll` and `afterAll` are used to run a function before and after, respectively, all the tests in a suite. Likewise, `beforeEach` and `afterEach` run a function before and after each test is run. For example, here is a common pattern from [DebugModelMatrixPrimitiveSpec.js](https://github.com/CesiumGS/cesium/blob/main/Specs/Scene/DebugModelMatrixPrimitiveSpec.js):

```javascript
var scene;
let scene;

beforeAll(function () {
scene = createScene();
Expand All @@ -330,7 +330,7 @@ Above, `scene` is scoped at the suite-level, so all tests in the file have acces

```javascript
it("renders", function () {
var p = scene.primitives.add(new DebugModelMatrixPrimitive());
const p = scene.primitives.add(new DebugModelMatrixPrimitive());
expect(scene).notToRender([0, 0, 0, 255]);
});
```
Expand Down Expand Up @@ -367,7 +367,7 @@ CesiumJS adds several custom Jasmine matchers to make the rendering tests more c

```javascript
it("renders", function () {
var p = scene.primitives.add(new DebugModelMatrixPrimitive());
const p = scene.primitives.add(new DebugModelMatrixPrimitive());
expect(scene).notToRender([0, 0, 0, 255]);
});

Expand Down Expand Up @@ -410,7 +410,7 @@ For reliability across WebGL implementations, use complex expectations in `toRen
Similar custom matchers are used for picking tests:

```javascript
var b = billboards.add(/* ... */);
const b = billboards.add(/* ... */);
expect(scene).toPickPrimitive(b); // Can also use toPickAndCall() and toDrillPickAndCall()

b.show = false;
Expand Down Expand Up @@ -450,7 +450,7 @@ Uniforms, the model matrix, and various depth options can be provided. In additi

```javascript
it("can declare automatic uniforms", function () {
var fs =
const fs =
"void main() { " +
" gl_FragColor = vec4((czm_viewport.x == 0.0) && (czm_viewport.y == 0.0) && (czm_viewport.z == 1.0) && (czm_viewport.w == 1.0)); " +
"}";
Expand All @@ -466,7 +466,7 @@ it("can declare automatic uniforms", function () {
GLSL is the shading language used by WebGL to run small graphics programs in parallel on the GPU. Under-the-hood, CesiumJS contains a library of GLSL identifiers and functions. These are unit tested by writing a simple fragment shader that outputs white if the test passes. For example, here is an excerpt from [BuiltinFunctionsSpec.js](https://github.com/CesiumGS/cesium/blob/main/Specs/Renderer/BuiltinFunctionsSpec.js);

```javascript
var context;
let context;

beforeAll(function () {
context = createContext();
Expand All @@ -477,7 +477,7 @@ afterAll(function () {
});

it("has czm_transpose (2x2)", function () {
var fs =
const fs =
"void main() { " +
" mat2 m = mat2(1.0, 2.0, 3.0, 4.0); " +
" mat2 mt = mat2(1.0, 3.0, 2.0, 4.0); " +
Expand All @@ -504,9 +504,9 @@ Here is an excerpt from [TweenCollectionSpec.js](https://github.com/CesiumGS/ces

```javascript
it("add() adds with a duration of zero", function () {
var complete = jasmine.createSpy("complete");
const complete = jasmine.createSpy("complete");

var tweens = new TweenCollection();
const tweens = new TweenCollection();
tweens.add({
startObject: {},
stopObject: {},
Expand All @@ -525,7 +525,7 @@ Spies can also provide more information about the function call (or calls). Here

```javascript
it("Zooms to longitude, latitude, height", function () {
var viewModel = new GeocoderViewModel({
const viewModel = new GeocoderViewModel({
scene: scene,
});

Expand Down Expand Up @@ -555,7 +555,7 @@ it("Applies the right render state", function () {
spyOn(RenderState, "fromCache").and.callThrough();

return loadModelJson(texturedBoxModel.gltf).then(function (model) {
var rs = {
const rs = {
frontFace: WebGLConstants.CCW,
cull: {
enabled: true,
Expand Down Expand Up @@ -593,14 +593,14 @@ For asynchronous testing, Jasmine's `it` function uses a `done` callback. For be
Here is an excerpt from [ModelSpec.js](https://github.com/CesiumGS/cesium/blob/main/Specs/Scene/ModelSpec.js):

```javascript
var texturedBoxUrl = "./Data/Models/Box-Textured/CesiumTexturedBoxTest.gltf";
var texturedBoxModel;
const texturedBoxUrl = "./Data/Models/Box-Textured/CesiumTexturedBoxTest.gltf";
const texturedBoxModel;

var cesiumAirUrl = "./Data/Models/CesiumAir/Cesium_Air.gltf";
var cesiumAirModel;
const cesiumAirUrl = "./Data/Models/CesiumAir/Cesium_Air.gltf";
const cesiumAirModel;

beforeAll(function () {
var modelPromises = [];
const modelPromises = [];
modelPromises.push(
loadModel(texturedBoxUrl).then(function (model) {
texturedBoxModel = model;
Expand All @@ -622,7 +622,7 @@ Here is an implementation of `loadModel`:

```javascript
function loadModelJson(gltf) {
var model = primitives.add(new Model());
const model = primitives.add(new Model());

return pollToPromise(
function () {
Expand All @@ -643,7 +643,7 @@ Since loading a model requires asynchronous requests and creating WebGL resource

```javascript
it("can create a billboard using a URL", function () {
var b = billboards.add({
const b = billboards.add({
image: "./Data/Images/Green.png",
});
expect(b.ready).toEqual(false);
Expand All @@ -662,9 +662,9 @@ To test if a promises rejects, we call `fail` in the resolve function and put th

```javascript
it("rejects readyPromise on error", function () {
var baseUrl = "//tiledArcGisMapServer.invalid";
const baseUrl = "//tiledArcGisMapServer.invalid";

var provider = new ArcGisMapServerImageryProvider({
const provider = new ArcGisMapServerImageryProvider({
url: baseUrl,
});

Expand Down Expand Up @@ -692,7 +692,7 @@ function MockPrimitive(command) {
}

it("debugCommandFilter filters commands", function () {
var c = new DrawCommand({
const c = new DrawCommand({
pass: Pass.OPAQUE,
});
c.execute = function () {};
Expand Down Expand Up @@ -724,7 +724,7 @@ import createScene from "../createScene.js";
describe(
"Scene/DebugModelMatrixPrimitive",
function () {
var scene;
let scene;

beforeAll(function () {
scene = createScene();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/ArcGISTiledElevationTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ALL_CHILDREN = 15;
* If neither parameter is specified, the WGS84 ellipsoid is used.
*
* @example
* var terrainProvider = new Cesium.ArcGISTiledElevationTerrainProvider({
* const terrainProvider = new Cesium.ArcGISTiledElevationTerrainProvider({
* url : 'https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer',
* token : 'KED1aF_I4UzXOHy3BnhwyBHU4l5oY6rO6walkmHoYqGp4XyIWUd5YZUC1ZrLAzvV40pR6gBXQayh0eFA8m6vPg..'
* });
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/AxisAlignedBoundingBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function AxisAlignedBoundingBox(minimum, maximum, center) {
*
* @example
* // Compute an axis aligned bounding box enclosing two points.
* var box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);
* const box = Cesium.AxisAlignedBoundingBox.fromPoints([new Cesium.Cartesian3(2, 0, 0), new Cesium.Cartesian3(-2, 0, 0)]);
*/
AxisAlignedBoundingBox.fromPoints = function (positions, result) {
if (!defined(result)) {
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ BoundingSphere.fromRectangle3D = function (
* // Compute the bounding sphere from 3 positions, each specified relative to a center.
* // In addition to the X, Y, and Z coordinates, the points array contains two additional
* // elements per point which are ignored for the purpose of computing the bounding sphere.
* var center = new Cesium.Cartesian3(1.0, 2.0, 3.0);
* var points = [1.0, 2.0, 3.0, 0.1, 0.2,
* const center = new Cesium.Cartesian3(1.0, 2.0, 3.0);
* const points = [1.0, 2.0, 3.0, 0.1, 0.2,
* 4.0, 5.0, 6.0, 0.1, 0.2,
* 7.0, 8.0, 9.0, 0.1, 0.2];
* var sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);
* const sphere = Cesium.BoundingSphere.fromVertices(points, center, 5);
*
* @see {@link http://blogs.agi.com/insight3d/index.php/2008/02/04/a-bounding/|Bounding Sphere computation article}
*/
Expand Down Expand Up @@ -749,7 +749,7 @@ BoundingSphere.fromEncodedCartesianVertices = function (
*
* @example
* // Create a bounding sphere around the unit cube
* var sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));
* const sphere = Cesium.BoundingSphere.fromCornerPoints(new Cesium.Cartesian3(-0.5, -0.5, -0.5), new Cesium.Cartesian3(0.5, 0.5, 0.5));
*/
BoundingSphere.fromCornerPoints = function (corner, oppositeCorner, result) {
//>>includeStart('debug', pragmas.debug);
Expand All @@ -774,7 +774,7 @@ BoundingSphere.fromCornerPoints = function (corner, oppositeCorner, result) {
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
*
* @example
* var boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);
* const boundingSphere = Cesium.BoundingSphere.fromEllipsoid(ellipsoid);
*/
BoundingSphere.fromEllipsoid = function (ellipsoid, result) {
//>>includeStart('debug', pragmas.debug);
Expand Down Expand Up @@ -1152,9 +1152,9 @@ BoundingSphere.distanceSquaredTo = function (sphere, cartesian) {
* @returns {BoundingSphere} The modified result parameter or a new BoundingSphere instance if none was provided.
*
* @example
* var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
* var boundingSphere = new Cesium.BoundingSphere();
* var newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);
* const modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(positionOnEllipsoid);
* const boundingSphere = new Cesium.BoundingSphere();
* const newBoundingSphere = Cesium.BoundingSphere.transformWithoutScale(boundingSphere, modelMatrix);
*/
BoundingSphere.transformWithoutScale = function (sphere, transform, result) {
//>>includeStart('debug', pragmas.debug);
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/BoxGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const diffScratch = new Cartesian3();
* @demo {@link https://sandcastle.cesium.com/index.html?src=Box.html|Cesium Sandcastle Box Demo}
*
* @example
* var box = new Cesium.BoxGeometry({
* const box = new Cesium.BoxGeometry({
* vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
* maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),
* minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)
* });
* var geometry = Cesium.BoxGeometry.createGeometry(box);
* const geometry = Cesium.BoxGeometry.createGeometry(box);
*/
function BoxGeometry(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Expand Down Expand Up @@ -80,11 +80,11 @@ function BoxGeometry(options) {
*
*
* @example
* var box = Cesium.BoxGeometry.fromDimensions({
* const box = Cesium.BoxGeometry.fromDimensions({
* vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
* dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)
* });
* var geometry = Cesium.BoxGeometry.createGeometry(box);
* const geometry = Cesium.BoxGeometry.createGeometry(box);
*
* @see BoxGeometry.createGeometry
*/
Expand Down Expand Up @@ -118,14 +118,14 @@ BoxGeometry.fromDimensions = function (options) {
*
*
* @example
* var aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
* const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
* -72.0, 40.0,
* -70.0, 35.0,
* -75.0, 30.0,
* -70.0, 30.0,
* -68.0, 40.0
* ]));
* var box = Cesium.BoxGeometry.fromAxisAlignedBoundingBox(aabb);
* const box = Cesium.BoxGeometry.fromAxisAlignedBoundingBox(aabb);
*
* @see BoxGeometry.createGeometry
*/
Expand Down
12 changes: 6 additions & 6 deletions Source/Core/BoxOutlineGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const diffScratch = new Cartesian3();
* @see Packable
*
* @example
* var box = new Cesium.BoxOutlineGeometry({
* const box = new Cesium.BoxOutlineGeometry({
* maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),
* minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)
* });
* var geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
* const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
*/
function BoxOutlineGeometry(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
Expand Down Expand Up @@ -71,10 +71,10 @@ function BoxOutlineGeometry(options) {
*
*
* @example
* var box = Cesium.BoxOutlineGeometry.fromDimensions({
* const box = Cesium.BoxOutlineGeometry.fromDimensions({
* dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)
* });
* var geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
* const geometry = Cesium.BoxOutlineGeometry.createGeometry(box);
*
* @see BoxOutlineGeometry.createGeometry
*/
Expand Down Expand Up @@ -107,14 +107,14 @@ BoxOutlineGeometry.fromDimensions = function (options) {
*
*
* @example
* var aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
* const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
* -72.0, 40.0,
* -70.0, 35.0,
* -75.0, 30.0,
* -70.0, 30.0,
* -68.0, 40.0
* ]));
* var box = Cesium.BoxOutlineGeometry.fromAxisAlignedBoundingBox(aabb);
* const box = Cesium.BoxOutlineGeometry.fromAxisAlignedBoundingBox(aabb);
*
* @see BoxOutlineGeometry.createGeometry
*/
Expand Down

0 comments on commit 63340e3

Please sign in to comment.