Geeks With Blogs
Sharpoverride The road to becomming a good programmer is paved with bad scripts

Usually the style you organize code is just that A MATTER OF STYLE, in javascript however it’s not.

If by any chance you end up writing the following code:

 

var display = function() {
    this.x = 10;
    return
    {
        alert: function(message) {
            window.alert(message);
        }
    }
}

you might be in for a surprise but it won’t return anything because by default the javascript interpreter inserts ; after every line that doesn’t already contain it or }.

Instead you should write:

var display = function() {
    this.x = 10;
    return {
        alert: function(message) {
            window.alert(message);
        }
    }
}

More interesting notes you can find in the next video:

Hope you enjoyed this I sure did :D.

Posted on Wednesday, August 12, 2009 1:34 PM | Back to top


Comments on this post: Javascript gotcha

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Sharpoverride | Powered by: GeeksWithBlogs.net