Browse Source

Distinguish rest parameter and spread operator (#83)

* Distinguish rest parameter and spread operator

The example for "spread operator" actually combines rest parameter and spread operator - although they use the same syntax they are different concepts.

* Clarify title
Jacob Mizraji 5 years ago
parent
commit
46c8923e90
1 changed files with 7 additions and 3 deletions
  1. 7 3
      threejs/lessons/threejs-prerequisites.md

+ 7 - 3
threejs/lessons/threejs-prerequisites.md

@@ -186,9 +186,9 @@ new code
  };
  };
 ```
 ```
 
 
-### Use the spread operator `...`
+### Use the rest parameter and the spread operator `...`
 
 
-The spread operator has a ton of uses. Example
+The rest parameter can be used to consume any number of parameters. Example
 
 
 ```js
 ```js
  function log(className, ...args) {
  function log(className, ...args) {
@@ -199,11 +199,15 @@ The spread operator has a ton of uses. Example
  }
  }
 ```
 ```
 
 
-Another example
+The spread operator can be used to expand an iterable into arguments, or copy an array
 
 
 ```js
 ```js
 const position = [1, 2, 3];
 const position = [1, 2, 3];
 somemesh.position.set(...position);
 somemesh.position.set(...position);
+
+const copiedPositionArray = [...position]
+copiedPositionArray.push(4) // [1,2,3,4] 
+console.log(position) // [1,2,3] position is unaffected
 ```
 ```
 
 
 ### Use `class`
 ### Use `class`