static functions, object.assign

master
Matt Huntington 7 years ago
parent e8979ff6ae
commit 2844b28af0

@ -21,6 +21,7 @@
1. Object literal extensions 1. Object literal extensions
1. Destructuring 1. Destructuring
1. swap (desconstucturing method) 1. swap (desconstucturing method)
1. Merge objects
<!-- other options: <!-- other options:
@ -317,6 +318,9 @@ me.logName();
```JavaScript ```JavaScript
class Cat { class Cat {
static getTypes(){
return ['large', 'small'];
}
constructor(name) { constructor(name) {
this.name = name; this.name = name;
} }
@ -345,6 +349,8 @@ var myLion = new Lion("Simba");
console.log(myLion.makesNoises()); console.log(myLion.makesNoises());
console.log(myLion.purrs()); console.log(myLion.purrs());
console.log(myLion.eatHuman()); console.log(myLion.eatHuman());
console.log(Cat.getTypes());
``` ```
## for...of ## for...of
@ -722,3 +728,34 @@ var y = false;
console.log(x,y); console.log(x,y);
``` ```
## Merge objects
You can use `Object.assign()` to merge properties of two or more objects:
```javascript
var a = {
foo:'bar'
}
var b = {
awesome:true
}
Object.assign(a, b);
console.log(a);
```
This is extremely useful when you need to create a brand new object that is a clone of another one with some minor changes (happens all the time with Redux):
```javascript
var bob = {
name:'Bob',
age: 42
}
var sally = Object.assign({}, bob, {name:'Sally'})
console.log(sally);
```

Loading…
Cancel
Save