Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
I have been doing quite a bit of domain modeling using functional programming mostly in Scala. And as it happens when you work on something for a long period of time you tend to identify more and more patterns that come up repeatedly within your implementations. You may ignore these as patterns the first time, get a feeling of mere coincidence the next time, but third time really gives you that aha! moment and you feel like documenting it as a design pattern. In course of my learnings I have started blogging on some of these patterns - you can find the earlier ones in the series in:
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
It's hard to believe that at this time last year, I knew little to nothing about JavaScript. Like any good neophyte, I started off reading Douglas Crockford's "The Good Parts", which is an excellent book except for the section on Closures. Closures are famously tricky to understand, so I tried extra hard. Even after slogging my way through every technical detail, I still wasn't sure if I was "getting it". Like, okay there's functional scoping, but so what?
So now I present to you a useful application of closures (inspired by this great article on Closures in Python):
Attaching data to a function
Let's pretend I'm the owner of a website called DaBomb.com. We sell headphones and snowboards.
1. To fetch a list of all the headphones on our site, I call:
I am tired of seeing my API url clutter up my code. What can I do? I can use a closure to make a new function that knows my API url:
function makeGetProductsFunction(apiUrl) { var getProducts = function (params, callback) { // apiUrl is "closed" in the definition of getHeadphones return $.get(apiUrl, params, callback); } return getProducts; }
Now my code looks like this:
var getHeadphones = makeGetProductsFunction('www.dabomb.com/items/headphones'); // this is a function
1. To fetch a list of all the headphones on our site: