How to Test if a Function Exists in Javascript

I’m no Javascript expert and I couldn’t work out why it seemed to be so difficult to test to see if a function existed before I called it. In the end Google provided a better way though it wasn’t the most popular suggestion out there, to me it seems the most sensible way:

    if (window.myFunctionName) {
        myFunctionName();
    }

Where myFunctionName is the function you’re testing for, of course.

Advertisement

Potential Problem with the Grails RichUI Plugin AutoComplete Tag

I’ve been using the Grails RichUI plugin and have found a few of the tags it provides to be very useful. The one I’m using the most is the AutoComplete tag which I may well be writing more about in the near future. However, tonight I found a potential issue with the way it creates the YUI data source for the component – it seems it always gives it the same name: ‘autoCompleteDataSource’.

Continue reading