Thursday, March 15, 2012

JS OOP and kestrel nest box research

Today's goal is to implement JavaScript objects.  I am familiar with OOP in Flex(ActionScript), PHP and other languages from years ago. However, JavaScript's lack of classes will require some re-routing of my neural circuitry.

I am starting my research with these two articles by Douglas Crockford:

The first object I have to create is to represent a kestrel nest box. (Want to build one? - A real box, not a JS object to represent one- Instructions here)  The box has parameters including height, width, depth, height off ground, entrance diameter, direction the entrance faces, what the box is mounted on, and more.

My current project will allow researchers across North America (and maybe South America too) to track data from their kestrel boxes. Using OOP and MVC methods will be essential to keep the software flexible enough to satisfy the preferences of such a diverse audience and allow future expansion of the project.

Update 10:35

More valuable references:

Update 17:40

I successfully met my goal. In some ways it was easier than expected, but at the same time, a bit confusing. My object is created simply by retrieving the parameters from the database, via jQuery's Ajax functionality, as JSON.

var request = $.ajax({
    url: "getBoxParams.php",
    type: "POST",
    data: {id : nestBoxClicked, user: userToken},
    dataType: "JSON"

request.done(function(boxData) {
     var kbox=new nestBox(boxData);                    

Then, I manipulate the object properties in the populateBoxForm() function.

I still prefer working with strongly typed languages and classes, but it appears JavaScript can do what I need for a fully-functional web app, without losing speed or user-friendliness.

Douglas Crockford's article about JavaScript code conventions is another good resource I found today. 

No comments:

Post a Comment