Hein (fub) wrote,
Hein
fub

  • Mood:

Hacking Javascript

This week, I have been hacking a site together for klik's photo expedition.

She gave me a raw sketch of how it should look, and how it should behave. Re-using the CMS I wrote for Creative Contraptions (which still isn't online) for this site would be overkill and require some rework of the system, so that was not a viable option. But building every page by hand also was not an option.

So I devised a cunning plan to create a site that is completely built up through DHTML. Specifying the site structure is only a matter of calling a Javascript function repeatedly with the right parameters -- something that klik can do herself. Maintaining the site then doesn't require any intervention from me, as it should be.

I decided to take the plunge and use Javascript OOP (or maybe I should call it 'OIP': Object Inspired Programming...). Works pretty well, except for one quirk that took me an hour to solve.
If you have an Array of objects, you can traverse the array in two ways: either you use a for-loop with an integer to index every item in the Array, or you use a "for (var x in Array)" construct. In the latter manner, your variable is not recognised as an Object -- but in the first, it is.

Why this is, is completely beyond me.
Tags: technology
Subscribe

  • Expanding my network

    I haven’t been posting here that much — partly because I don’t have much to say. But I haven’t been off the internet, of…

  • Things that happened this week

    A power interruption. We had gotten a letter from the company that manages the power lines that they’d be working on the infrastructure on…

  • The Forest Shrine released!

    In the early stages of 2020, I released my scenario The Secret of Cedar Peak, a scenario for fifth edition Dungeons & Dragons. I had a sequel…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 5 comments