0

I am having a javascript error on my site http://fightgifs.com with this line of code in footer.php:

var main_menu=new main_menu.dd("main_menu");

Uncaught TypeError: Cannot read property 'dd' of undefined

Anyone has an idea what to do ? The error is creating a problem for a javascript plugin (Shashin). Whole script:

<script type="text/javascript">

jQuery(document).ready(function($){

$('.carousel').elastislide({

    imageW  : 145,

    minItems    : 2,

    margin      : 10

});

var main_menu=new main_menu.dd("main_menu");

main_menu.init("main_menu","menuhover");

});

</script>

2 Answers 2

2

The main_menu you expected this to refer to is actually being shadowed.

var main_menu = new main_menu.dd("main_menu");

Both mentions of main_menu actually refer to the local variable being declared, which will be undefined rather than an object with a .dd() method.

To avoid this, you'll have to rename one of them.

var menu = new main_menu.dd("main_menu");

menu.init("main_menu","menuhover");

Or, if you don't need the var afterwards, you can also skip it:

new main_menu.dd("main_menu")
    .init("main_menu","menuhover");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for helping, however now I get Uncaught ReferenceError: main_menu is not defined
@MartinLaumets Well, that depends on what main_menu was expected to be and what is supposed to be defining it. It might actually have a different name. It might be a property of another object rather than a global. If it's from a WordPress plugin, it could be that some the plugin's files aren't being included in the pages.
0

Your code of main_menu object has a problem. Post your code related to main_menu or check code yourself.

1 Comment

it's also probably a bad idea to redefine the object to a variable . . .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.