Elegant code vs ‘just making it work’

I love being clever. I love clever little tricks, clever little bits of code. So when I’m trying to pass several rows of data from a Php script into Javascript so I can use it to put markers on a Google Map. The really clever thing to do would be to create an array of objects in Php, encode them into JSON and then decode the JSON and use the object notation for each instance of the object

class Incident{
public $incidentDate;
public $desc;
public $latitude;
public $longitude;

public function _construct($incidentDate, $desc, $latitude, $longitude){
$this->incidentDate = $incidentDate;
$this->description = $desc;
$this->latitude = $latitude;
$this->longitude = $longitude;
}
}

But can I make it work?? Nope. So I’ve JSON’ed up each array, passed them in and then used the Javascript Array.prototype.map method to populate my arrays and create my oh so clever markers. Now, should I get them to bounce or not……………………

Leave a Reply

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