Wednesday, May 14, 2008

missing ( before formal parameters


I ran across this little error the other day when I ran some javascript that was working fine in IE but Firefox just didn't like.
It was pretty easy, but vague, to track down what Firefox was complaining about and it was just another difference between JScript and Javascript ugh.
Here's a little example of what was causing this issue.

<script type="text/javascript">
// just create some dummy variables for namespaces
var some = {};
some.namespace = {};

(function($) {
function $.testFunc() { /*some code here*/ }
})(some.namespace);
</script>

The problem is when creating the testFunc function. JScript allows the '.' in the declaration and Javascript does not. Here is a quick and simple fix for this that will work in both IE and Firefox (and Safari).

<script type="text/javascript">
// just create some dummy variables for namespaces
var some = {};
some.namespace = {};

(function($) {
$.testFunc = function() { /*some code here*/ }
})(some.namespace);
</script>