0

According to this post Click here to see the referred post

I tried to get access to a function which is defined in another .js file following the post instruction. However, I still have a problem. See my code below:

sildemenu.js

$(document).ready(function() {
    var window.slideMenu=function(){
        //do something here 
    }();
});

control.js

$(document).ready(function() {
    $('#foo').on('click', function() {
         window.slideMenu();
    });
});

I got the error "Object [object Window] has no method 'sildeMenu' ". I am very new in programming. Please give me a mercy.

2
  • 1
    Execution of sildemenu.js fails because var window.slideMenu is a syntax error (and the issue gdoron mentions). Drop the var. I recommend to read netmagazine.com/tutorials/javascript-debugging-beginners. Commented Feb 20, 2013 at 10:11
  • If you read the linked question/answer properly, you will see that there are no () after the function definition and no var before window..... Commented Feb 20, 2013 at 10:15

2 Answers 2

1

You try to define a complex variable, (which is impossible this way) instead of assign a value to the global object- window.

  var window.slideMenu=function(){
//^^^ Get rid of this
    //do something here 
  }();
 //^^  and remove this

And get rid of the var Fixed code:

window.slideMenu=function(){
    //do something here 
};
Sign up to request clarification or add additional context in comments.

1 Comment

I did apply your Fixed code, however, I still got the same error. It seems like slidemenu.js is fine but the error comes from control.js.
1

There is no need of window object just write:

sildemenu.js

$(document).ready(function() {
    slideMenu=function(){
      //Do your stuff here!
    };
});

control.js

$(document).ready(function() {
    $('#foo').on('click', function() {
         slideMenu();
    });
});

Comments

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.