Marek Augustyn
Jul 25, 2017 · 1 min read

Hi, good reading!

In the last example without stamps you bind the function:

export default function storeDocument(
{userID, folderLocation, fileStream}
) {
const {resolveUserAccess, fileStorage} =
Object.assign({}, defaults, this); // this!!!
return resolveUserAccess({userID, folderLocation})
.then(({user, folder}) =>
fileStorage.save(fileStream, {user, folder})
);
}.bind(defaults); // binding to the `default` context!!!

It exports storeDocument as a bounded function. Then you try to call it with different context:

storeDocument.call(
mockDependencies,
{userID, folderLocation, fileStream}
)

which doesn’t work because storeDocument is already bounded to defaults, so mockDependencies are not accessible by this.

Am I missing something?

    Marek Augustyn

    Written by

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade