Posts Tagged “JavaScript”

image

Sentence a String to Capital Punishment.

A simple function to help dynamically capitalize text and an excuse to try writing script with the WebMaster Android app, then post it from the WordPress Android app. Nice little script editor for a smart phone or tablet.

Even though this function and post are small, writing them from a little smart phone is "capital" punishment. After previewing my post I ending up logging into a desktop browser anyway to correct formatting which the WordPress mobile app could not handle from my script example below. Writing script from a small device is also uncomfortable. Using a tablet would be easier but does not necessarily make a lighter "sentence".


<script type="text/javascript">
var word="keith";
document.write(word);
/**
* Capitalizes the first letter of String.*
**/
function capitalize(W)
{
    return W.substr(0,1).toUpperCase()+W.substr(1,W.length);
}
</script>

Comments No Comments »

String'n together combos isn't always as fun as doing them in a fighting videogame.

If you write script that has a lot String content mixed with variables, I'm sure you're doing a lot of heavy concatenation.
Building string combos with quotes and apostrophes sprinkled all over a script gets confusing. The way I like to keep this confusion to a minimum is to write my static markup separately. This allows me to make sure it shows up as intended. Then I concatenate my variables in all the places that need to have dynamic content.

Taking static markup or script and wrapping quotes around every line is a chore so I made this Concatenation Tool to help with that.

Currently I've only made this support languages I'm using mostly. If I have to use a new language I'd just add it in.
Read the rest of this entry »

Comments 2 Comments »

 

 

 

 

 

 

 

I been writing JavaScript recently and had to conjure up the older syntax I'd usually write in ActionScript 2
This post is possibly "beating a dead horse" but I'll post it anyway.

JavaScript or ActionScript 2

  1. function isArray(o)
  2. {
  3. return o instanceof Array;
  4.  
  5. //Alternative way
  6. //return Object(o.constructor) == [].constructor;
  7. }
  8.  
  9. var A=new Array();
  10. var B=new Object();
  11. var C="dog";
  12. var D=function(){};
  13.  
  14. alert(isArray(A)+","+isArray(B)+","+isArray(C)+","+isArray(D));
  15.  
  16. //Outputs: true,false,false,false

ActionScript 3

  1. function isArray(o:Object=null):Boolean
  2. {
  3. return o is Array;
  4. }
  5.  
  6. var A:Array=new Array();
  7. var B:Object=new Object();
  8. var C:String="dog";
  9. var D:Function=function(){};
  10.  
  11. trace(isArray(A)+","+isArray(B)+","+isArray(C)+","+isArray(D));
  12.  
  13. //Outputs: true,false,false,false

Comments No Comments »

Thanks for visiting www.keith-hair.net