Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Reducer(counter : number = 0, action : Action) {
- counter++; // Should trigger an error but it doesn't.
- return counter + 1;
- }
- function NestedReducer(nestedCounter : { counter : number } = { counter : 0 }, action : Action) {
- nestedCounter = { counter : 0 }; // Doesn't trigger an error.
- nestedCounter.counter++; // This does trigger an error.
- return { counter : nestedCounter.counter + 1 };
- }
- let a = { counter : 0 };
- let b = a;
- console.log(`${a.counter}, ${b.counter}`);
- b.counter++; // This changes a.counter as well since both a and b reference the same object.
- console.log(`${a.counter}, ${b.counter}`);
- b = { counter : 0 }; // This does not change a or a.counter, now a and b point to different objects.
- console.log(`${a.counter}, ${b.counter}`);
- 0, 0
- 1, 1
- 1, 0
Add Comment
Please, Sign In to add comment