0

I have this big "class".

function MyFunc(){
    this.prop = true;
}

MyFunc.prototype.method1 = function(){
    // code here
}

etc, lots of methods in one file. and then, the instance is created and run on document.ready

And then, I have one particularly large method, that I would like to move to a separate file. However, when I move it and include them one after another, main file first, the second one says MyFunc is not defined. I cannot add that prototype.method declaration on document.ready, also, since it has to be ready before instance is initialized. What pattern should I use here to properly organize my code? Thanks.

Alex.Me
  • 616
  • 3
  • 11
  • You should probably be using modules. Look into Browserify for example, or AMD. – elclanrs Dec 30 '14 at 04:53
  • 1
    This should have nothing to do with waiting for the document to be ready. I would guess that your `MyFunc` is inside another function. If so, make it global, in a namespace preferably with all your other data that needs to be globally accessible. – six fingered man Dec 30 '14 at 04:55
  • Make sure that you write your scripts after you have loaded the function. Generally including the file first and writing codes depenedent on that file later should do, you can always use $("script").onload = .. or promises if you want to. http://stackoverflow.com/questions/3809862/can-we-call-the-function-written-in-one-javascript-in-another-js-file – argentum47 Dec 30 '14 at 04:57
  • Thanks, six fingered man, that was it!) – Alex.Me Dec 30 '14 at 05:01

0 Answers0