I tried to pin this down (without reference to the actual language spec, so apologies if I get any details incorrect)
- What is the function object whose definition contains the code currently executing?
- What kind of syntax was used at the point this particular function object was called?
- Called explicitly as a property of an object, as in: someObject.propertyName(someArg), where someObject.propertyName == yourFunction
- Then 'this' is 'someObject' from the above. this is the most common way for the value of 'this' to be decided.
- As yourFunction.call(abc, someArg), or yourFunction.apply(abc, [someArg])
- Then 'this' is 'abc' from the above
- Neither of the above - when called as eg someLocalVariable() or someGlobalVariable()
- Within a 'with' block, as in with(foo) { yourFunction() }
- Then 'this' is 'foo' from the above
- At the top-level within javascript defined in a script tag in a browser
- Then 'this' is the 'window' object
- From the top-level in event handler code defined in an HTML attribute in a browser
- Then 'this' is the DOM element concerned
- From the top-level in some other javascript execution environment
- Implementation-defined
- When called by some code outside your control
- Could be anything
- If you want to fix the value of 'this', then before handing your function over as a callback, wrap it up inside an closure which explicitly calls apply with your intended value of this:
- var myFunction = some.expression; var callMeBack = function() { myFunction.apply(intendedFixedValueOfThis, arguments) }
- Or use eg Function.prototype.bind from prototype, dojo.hitch from dojo
My mum got this recipe when I was small from a Dutch friend called (I think!) Irma. Thanks Irma. It’s like shortbread but softer, sweeter and more buttery, it’s something that’s good and quite quick to make and so I’ve been trying to perfect it.
My basic recipe involves equal parts by weight of:
- Caster sugar
- Plain white flour
- Butter
(Yes that’s a lot of butter). Plus up to half a part of ground almonds if you have any.
I’ve experimented with adding very small quantities of orange zest and nutmeg, but there’s no great need for extra flavourings. Some stir an egg into the mixture too, which probably improves the moistness and consistency of the result but is something I’ve avoided with my mild egg alergy.
Slice the butter (left to soften a little beforehand won’t hurt) into the flour and sugar, rub in until you get a crumbly mixture. Press into a shallow cake tin or baking tray with a fork.
Preheat and cook for 10-20mins at around 200C. The timing seems to depend on your oven, the tin, how deep the mixture is etc, and it’s easy to overcook it - so watch closely. If it’s starting to get brown around the edges of the tin it’s probably had long enough.
Leave to cool; it should end up a bit soft in the middle (the tastiest bit), but it seems unavoidable that it will harden a bit more around the edges. If it’s hard all the way through though, then you cooked it too long or too high.
A quick tour of its neighbourhood in “ingredient ratio space” (something which I think every recipe should come with so you can understand the “why” not just the “what”):
- More sugar may result in more of a hard, crumbly, fudge-like biscuity sweet, depending how long you cook it. Less sugar results in more of a buttery shortbread.
- More flour results in, well, shortbread. Which is a bit boring. Less flour gives more of a sticky, fudgey biscuit
- More butter may result in something a bit too greasy, with the grease draining out of the cake leading to poor consistency and butter in the bottom of the tin. Less butter gives a sweet shortbread.
I need to collect more data on the cooking time vs temperature tradeoff. I suspect longer on lower heat might help evenness of the result, but shorter at higher a better consistency in the middle?
There are only two hard things in Computer Science: cache invalidation and naming things.
Attributed to Phil Karlton. Naming I know is hard, but does anyone have an example of why cache invalidation is a deep problem? I am considering a dependency graph (well, DAG) for cached pieces of data, with time-to-live values on the edges.