Uncategorized

Refactor #2

Well, I added a lot of stuff, and Connect! got messy again.  Also, I think I’m evolving in the way I do my JSHTML projects, so my style is changing, which means I need to go through and make stuff consistent again.

I’ve pretty much touched every script file in the project making a handful of functions into an object instead.

One of the things  I really like aboutJavaScript is the easy way I can go from:

function  createThings(){/*…*/}

function showThings() {/*…*/}

function  hideThings(){/*…*/}

to:

var things=

{

“create”:function(){/*…*/},

“show”:function(){/*…*/},

“hide”:function(){/*…*/}

};

I’m starting to build up a pretty good library of objects that are reusable. For example, I have a htmlGenerator object that can make tags for me given the following:

htmlGenerator.createTag

(

{

“tag”:”img”,

“attributes”:

{

“id”:”theImage” ,

“src”:”images/theimage.png”
},

“styles”:

{

“position”:”absolute”,

“left”:”16px”,

“top”:”16px”

}
}

);

Which will spit a string that contains:

<img id=”theImage” src=”images/theimage.png” style=”position:absolute;left:16px;top:16px;”>

And this may lead you to question “What does this gain?”

Now I can manipulate tag descriptor objects (say in an array) and use the same descriptor object multiple times.

Anyway, I find this more useful than my old way of just writing the text out.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s