January 2020
Intermediate to advanced
470 pages
11h 13m
English
There is, however, a case that you should be aware of: what happens if you are calling an object's method? Look at the following code:
fetch("some/remote/url").then(function(data) { myObject.store(data);});
If your original code had been something along the lines of the preceding code, then the seemingly obvious transformed code would fail:
fetch("some/remote/url").then(myObject.store);
Why? The reason is that in the original code, the called method is bound to an object (myObject), but in the modified code, it isn't bound and is just a free function. We can then fix it in a simple way by using bind(), as follows:
fetch("some/remote/url").then(myObject.store.bind(myObject));
This is a general solution. When dealing with ...
Read now
Unlock full access