Sunday, April 08, 2012

Learning Javascript

Though we're using Rails as our framework, Picket Report's code base is only 45% Ruby and 55% Javascript. I didn't have much experience with Javascript until the past month or so, and though the syntax is a little cumbersome at first, I've started to enjoy using the language, particularly creating and handling Javascript objects.

Most APIs that I've dealt with so far respond with JSON objects, but it wasn't until the last two or three weeks that I got more comfortable understanding how get to what I wanted within a response. Part of it was learning how to use console.debug() and thus being able to actually see the object and how it was structured, but most of my improvement can be chalked up to learning some basic Javascript - looping, if/then statements, creating objects for later use, etc.

A basic example from this past week. I created a marker ID object that kept track of each google maps marker on my map as well as a string of html content I wanted to appear in a map popup/infowindow when the user clicked on a marker. I organized the object by marker ID so that I could easily find that marker at a later point. I couldn't have done this a couple of weeks ago, and when it came together it was a nice reminder of how much I've learned and a big aha moment that seemed to open up a sense of possibility...


 markerIDObject[marker.__gm_id] = {};
 markerIDObject[marker.__gm_id].marker = marker;
 markerIDObject[marker.__gm_id].content = contentString;


 this.neighborhoodShowInfoWindowBounce = function(marker_id) {
    showInfoWindow(markerIDObject[marker_id].marker, markerIDObject[marker_id].content);
    markerBounce(markerIDObject[marker_id].marker);
  }


2 comments:

  1. JSON is not for making markers. You should be using PHP. I often come across young programmers like yourself getting languages confused. This would explain why your code file is 45% Ruby and 55% Javascript!!!

    If you would just use PHP as your programming language then the computer will not give you JSON errors and your code file would be 100% PHP and you would not have to blog about your troubles.

    I would very much like to meet you. I am from ferndale and have a facebook. If you go on the facebook and enter in my name you will find me and we can meet at Red Robins burger store. At Red Robins burger store I can teach you about computers and we can have BOTTOMLESS FRENCH FRIES :)

    PS - If you are having trouble with too many markers in Google Maps, you can go to File, new Window in your internet explorer tools and it will give you another place to visit google maps and find different areas without too many markers!!

    ReplyDelete
  2. Creative and professional applications have been creating by ruby on rails development company to meet the requirements of the clients.so you must hire ror programmers who are very best at their skills to safe your time and money.
    ror development company

    ReplyDelete