Monday, September 21, 2009


Auto-generating JavaScript code

Languages which are trying to be smarter make it harder to auto-generate code.

Indeed, I wrote a small piece of code to output JavaScript Array, something along these lines (Python):

write ("var myarr=Array(" + ",".join([str( for  o in objects]) + "); \n")

Of course, it was working just fine till I encountered a case where length of incoming Python list objects is one, where it immediately broke, because meaning of JavaScript initialization

var myarr=Array(10);

is not at all what the above piece of code was silently expecting.

Labels: , ,

This page is powered by Blogger. Isn't yours?