Comments (7)
I'm no expert, but I figured from reading it that they were addressing mutable vs. immutable data constructs. They even admit in the explanation paragraph (currently anyway) that it is slower than mutating the object:
// Object.create() is perfect for functional programming because it
// makes creating a new object with a different member value almost
// as cheap as changing the member on the original object!
Edit: You can see a slightly more real world example of Object.create in exercise 37:
function(queue, movieListsMessage) {
var copyOfMovieLists = Object.create(movieListsMessage.list);
if (queue !== undefined) {
copyOfMovieLists.push(queue);
}
return copyOfMovieLists;
});
They call the variable copyOfMovieLists
, so it looks like it's a nifty way to do an immutable copy of a list.
from learnrx.
As @bill-mybiz said, I'm not expert but I think he's right: mutating the original copy through out the call stack would be considered a "side effect" and not very "functional". Creating and returning a new copy would preserve state of the input of each call while still giving you the correctly mutated copy on return.
from learnrx.
Hmm, I understand
90% speed penalty is definitely too much for real world use though.
I was curious as to how a typical immutable JS library would perform, check it out
http://jsperf.com/object-create-vs-mutation-in-reduce/4
50% penalty this time.
Would love to see even better perf
from learnrx.
Aside from performance, it makes testing a pain, because Jasmine won't look at the prototype properties.
from learnrx.
@gabrielkunkel In that case, would Object.assign be a better alternative and it turns out that Object.assign is faster than Object.create at least according to the below test which is edited from test from @prashcr
http://jsperf.com/object-create-vs-mutation-in-reduce/6
from learnrx.
would both create and assign achieve the desired effect?
from learnrx.
@varungupta85 Yes! Aside from being a little bit faster than Object.create(), Object.assign() is more testable with Jasmine. (Solves the issue I ran into while going through the tutorial.)
@morenoh149 They do different things, but for the sake of the tutorial they do achieve the same desired effect.
See my pull request.
from learnrx.
Related Issues (20)
- Exercise 38 pre correction
- reduce().map() ? ex20 HOT 2
- Typos in exercises 16 and 13 HOT 2
- Revise lesson 36 and onward for the RxJS 5 API HOT 5
- Tutorials / Exercises for monads
- Exercise 29 - Wrong explanation HOT 7
- Reduce implementation on exercise 16 is wrong HOT 1
- Order of keys matters HOT 1
- Exercise 23 - broken? HOT 3
- Porting the exercises to codewars.com HOT 4
- Debugging
- rx library implementation? HOT 3
- exercise 3 and onwards broken HOT 3
- exercise 8 fails opening new exercise although the correct answer was submitted. HOT 2
- Enhancement - Any interest in a helper function to show exercise by number?
- Bug - Exercise 37 does not show a movie list HOT 1
- Exercise 26 another way
- Exercise 21 "Before" seems wrong
- Inserting braces cause dramatic indentation
- debounceTime is better for the autocomplete example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from learnrx.