Wordpress CodeHighlighter christening and javascript function is defined
October 13, 2005 – 10:40 pmSince I realize that I will be posting a bunch of code and other command line uses I decided to look into a code highlighting method. I came across a great solution at chroder.com. The only problem I had was with the way the height was determined on the boxes. I had to play around with this quite a bit to get it right, which is why the site was a bit wacky for the last day or so.
So to christen the new code highlighter, I give you the simple way to determine if a javascript function is defined.
[code lang="javascript"]
if(self.functionName) {
alert('function IS defined');
else {
alert(' function functionName is not defined');
}
[/code]
This is a significantly better option than try / catch, or an eval.
As as second item, I’ve had to store object names as strings in a javascript array alot lately. The easiest way to instantiate these objects not using eval is to use the window object as follows:
[code lang="javascript"]
var c = 'testClassName';
var nClass = new window[c];
[/code]
Now you’ve got a new object of type testClassName stored in nClass.
Sorry, comments for this entry are closed at this time.