The better utility belt Lodash

We switched from Underscore.js to Lodash compatibility mode and never been happier. (I’m a Web UI Developer situated in Singapore.)

Lodash is a drop-in replacement for Underscore.js, from the devs behind, that delivers performance improvements, bug fixes, and additional features.

It adds some additional functions too. Their collection tools are more comprehensive than Underscore.js’s. I had some issues doing a _.where through a mix of array and objects during web JavaScript programming. Lodash was the answer for it.

JSON.stringify then JSON.parse

I realized we keep doing JSON stringify then eventually parsing it back again and again to copy over objects. This does a dump “clone”, it ignores references and functions but is really fast. I wrote a Underscore.js or Lodash mixin just to do this.

[code lang=”javascript”]
* This is the shortcut for JSON.stringify then parsing it back.
* Quick access to simple object copying.
* It does not copy functions!
* @author KahWee Teng
* @return {Object} Lodash mixin object.
_.mixin((function() {
"use strict";
return {
copy: function(object) {
return JSON.parse(JSON.stringify(object));

There’s just so many ways to doing a clone but this is by far the fastest but then again it depends on your needs. Dump clone I call this.

Interesting discoveries #03

So! A fortnight has passed quickly due to the holidays in between. I wanted to make this post a weekly affair but I have my laziness to blame.

One interesting side effect to writing what I encounter is that it kinda slows me down reading which is welcomed. So these are the key things I discovered and/or rediscovered:

1. Backbone.js

I never had to touch this for a while. Backbone.js makes large JavaScript applications manageable again with MVC methodologies. I implore every JavaScript developer or enthusiast to at least make a todo list with this. More on the website.

2. Lo-Dash

One of the dependencies of Backbone.js is Lo-Dash (or Underscore.js) which promise some improvements. You can more about Lo-dash here. Lo-dash is designed as a drop in replacement for Underscore.js that provides better consistency among browsers. Take a look at this video:

3. Paid subscribers model a success online

Paid subscription model is actually working out for The New York Times. Not that it is expected not to work but that it is working better than expected. Digital subscriptions will generate $91 million this year, according to Douglas Arthur, an analyst with Evercore Partners. The paywall, by his estimate, will account for 12 percent of total subscription sales, which will top $768.3 million this year. That’s $52.8 million more than advertising. Those figures are for the Times newspaper and the International Herald Tribune, largely considered the European edition of the Times. Bloomberg has more.

4. Exporting old people

The question on ethics is called when Germans start to export their elderly to other countries with more affordable healthcare. This move is determined as an “inhumane deportation.” Guardian has more. According to Germany’s federal bureau of statistics, more than 400,000 senior citizens are currently unable to afford a German retirement home, a figure that is growing by around 5% a year.

Artur Frank, the owner of Senior Palace, which finds care homes for Germans in Slovakia, said that was why it was wrong to suggest senior citizens were being “deported” abroad, as the VdK described it.

“They are not being deported or expelled,” he said. “Many are here of their own free will, and these are the results of sensible decisions by their families who know they will be better off.”

5. Humans triumph over turtles

Clemson University student Nathan Weaver set out to determine how to help turtles cross the road. He ended up getting a glimpse into the dark souls of some humans.

Weaver put a realistic rubber turtle in the middle of a lane on a busy road near campus. Then he got out of the way and watched over the next hour as seven drivers swerved and deliberately ran over the animal. AP has more.

Really disturbing case this one is.

6. Superfreakonomics

I finished this book and find it okay. I haven’t read the first book so I can’t compare. It’s interesting to read things from a point of view of an economist. The way the book is written makes it hard to read though — there are just too many thoughts going on. The way one idea leads to another conflicting idea and then the economists brought about their own debates and deductions is somewhat distracting. However it might just be the way the mind works, there’s just too many things to digest. The book is engaging nevertheless. I heard the first book is better though. You can order it from Amazon.