Aikido, programming, system administration, and other things I find interesting

A gotcha with javascript objects


November 23, 2015


No Comment

Spent some time today figuring this one. I got too used to perl auto-vivifying objects (or hashes – same thing in Perl5).

It seems javascript does the opposite: if a member of of a structure is a string, and then you assign to it as if to an object, it will simply IGNORE your assignment. No error, no change in the assigned object, nothing.

Look at this code (or better yet, execute it in a debugger, step by step).

$(document).ready(function() {
var a = new Object;
var b = new Object;
a['b'] = b;
b['c'] = 'c';
a['b'] = JSON.stringify(b);

I know, of course that some languages are more strongly typed than others. But I never thought that I would find a case where it straight up ignored an assignment, without generating an error.

Related Posts

Munin-async 2.0.17 on Ubuntu 12.04


October 26, 2013


1 Comment

Munin authors have moved on in their development and if you are going to be installing munin-async on any system, I strongly recommend that you use the latest version (2.0.17 at the time of writing), which fixes a number of problems I described in a previous article on Installing munin-async. The only problem I had […]

Read More

Hello ripe64!

Ripe64 is starting in a few hours. I am a member of expert council, which is the local organizer of this RIPE meeting. The RIPE set up team is composed of amazing professionals, who obviously have a lot of experience setting up events like this, the setup went smoothly despite some unforseeable mishaps, like […]

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *