Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Closure notes
function bookSlotByCustId(customerId) {
const custId = customerId
return function bookSlot(slotId) {
//psuedo code here:
dispatch({
apiCall: api.bookSlot(custId, slotId)
});
}
}
const cId = 5
const bookMySlot = bookSlotByCustId(cId);
// bookMySlot is *just* a function
// assume "time has passed here"
// what i really mean is - we have lost the context of our cId variable
const sId = 6
bookMySlot(sId)
const InTrolleyCounter = (styleModifier, amountSuffix) => ({ productName, quantity }) => {
// do something with all 4 varaiables
}
function InTrolleyCounter (styleModifier, amountSuffix) {
return function({ productName, quantity }) {
// do something with all 4 varaiables
}
}
// we have stored 'style' and 'amount' at this point - they are bound to x now.
const x = InTrolleyCounter('style', 'amount')
// here we pass in the second set of args, which we can change whenever we call x
x('name', 1)
export default {
RoundelTrolleyCounter: InTrolleyCounter('roundel', ''),
BannerTrolleyCounter: InTrolleyCounter('', ' in trolley'),
AdaptiveBannerTrolleyCounter: InTrolleyCounter('adaptToViewport', ' in trolley'),
}
...
import ITC from 'introlleycounter';
const Roundel = ITC.RoundelTrolleyCounter;
Roundel('fred', '1')
render() {
return (<Roundel productName='fred' quantity='1' />)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment