Little jQuery.extend gotcha

jQuery.extend() is a very powerful function for merging two objects or for extending jQuery with custom plugins.

There is but one little gotcha to think about: as in most function calls the order of parameters matters 🙂

Following two fragments of code yields different objects

var a = {
  aa : '1'
  , bb : '2'
  , cc : '3'
};

var b = {
  aa : '11'
  , bb : '22'
  , dd: 3
};

var result_a = $.extend({}, true, a, b);
var result_b = $.extend({}, true, b, a);

The result will be this:

Notice that I use $.extend({}, true, a, b) instead of $.extend(a, b). The first parameter (which is optional) is the target which should receive merged properties. If none is given than the first object is extended automatically.

So, is the world really faster?

Every now and then I hear people complaining that the world is now much faster than it used to be in time of our grandparents. But is it really so? Did people complain about that very fact in their time? Another common complain is that parents now have less time for their children or their partners. I don’t agree with this. I think that generally we work less now, don’t we have 8 hours long work day? Problem is that we have now too many options to choose from. It is difficult to choose and be happy with your choice, when choosing one option means saying no to all other tempting options. We have twitter and facebook statutes, google reader, rss.. and so on and so on. The amount of information is so overwhelming, that we always miss something. We just can’t catch up on it all. Therefore the world seems so fast. It’s not that much about the progress and innovation pace but about the number of small choices and distractions you face every day.  So why not just slow down and enjoy simple (offline!) things?

As a programmer I tend to follow what’s going on in the industry. I love learning new stuff. So I read about new technologies, I try them, dream about using them. And I often feel kind of guilty that I can’t learn them all. I always feel quite behind. Incapable of following. I guess that lot of people have similar problem of trying to do too much.

After reading that sleep is more important then food I decided to try to slow down and really sleep more. Yes, it does help :). I don’ t always manage to get those recommended 8 hours per day, but when I do, I can tell the difference. I just focus much better when I am fully rested (surprise:) ).  One of the requirements to get more sleep and feel better is to drop something off. Make more free time for yourself. Then your world will be slower again as it should be.

Buffer
GetSocial