Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using AJAxsolr framework for building my search UI. I have an index file which is an html file. This file has all the necessary script imports that import the javascript files. I have a javascript file script1.js which has a function as follows:

  function myfunction(){
     //Do the necessary stuff
  }

I have another js file mywidget.js which is my custom widget. It has the following function:

  (function ($) {
     AjaxSolr.MyWidget = AjaxSolr.AbstractTextWidget.extend({
        init: function(){

        }
        // and other functions

     }
  });

I want to call the function myfunction() in script1.js from the mywidget.js file. I tried the $.getScript() function but couldn't get to call the function. Can someone help me on this please?

Thank you!

share|improve this question
    
make sure myfunction is defined above where you are calling it, and you should be fine. –  Tim Mac Jul 26 '13 at 17:48

1 Answer 1

You need to load the script1.js file before the mywidget.js file (ie. place one before the other in the HTML).

From there you should be able to call myFunction with no problems.

If after this you're still having issues, you can use $.fn.myFunction() to extend jQuery's prototype. In essence by doing this you'll be adding functionality to jQuery.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.