Created
April 5, 2012 02:54
-
-
Save miwillhite/2307640 to your computer and use it in GitHub Desktop.
Mind yo commas!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This snippet constructs an array of objects...via some server-side templating thing | |
// Now can you tell me what's wrong with this code? | |
// | |
// ... | |
// | |
<script language="javascript"> | |
var nouns = [ | |
{% for noun in nouns['people']: -%} | |
{ 'noun': '{{ noun.name }}', 'category':'People', 'slug':'{{ noun.slug }}' }, | |
{% endfor -%} | |
{% for noun in nouns['places']: -%} | |
{ 'noun': '{{ noun.name }}', 'category':'Places', 'slug':'{{ noun.slug }}' }, | |
{% endfor -%} | |
{% for noun in nouns['things']: -%} | |
{ 'noun': '{{ noun.name }}', 'category':'Things', 'slug':'{{ noun.slug }}' }, | |
{% endfor -%} | |
]; | |
</script> | |
// Take a look at line 21 -- that NASTY LITTLE COMMA | |
// | |
// Chrome: | |
[1,2,3,].length //=> 3 | |
// | |
// IE: | |
[1,2,3,].length //=> 4 | |
JSON.stringify([1,2,3]) //=> [1,2,3] | |
JSON.stringify([1,2,3,]) //=> [1,2,3,null] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment