1

Let's say I have an Object View original defined in one file View.js :

      var View = (function () {

      function View() {
      }

       View.prototype.SubFunc = function() {

      }   

      return View;
  })();

Now I want to be able to split in 2 files :

View.js

  var View = (function () {

      function View() {
      }

      return View;
  })();

and SubFunc.js

      View.prototype.SubFunc = function() {

      }   

Why it doesn't seem to work anymore ? During execution I get this error :

      view.SubFunc is not a function
1
  • 1
    Why would you want to split up the constructor like that? Commented Mar 8, 2016 at 6:08

1 Answer 1

1

JS files are imported one by one but asynchronously and there is no guarantee that file1 will be loaded before file2.

You can wrap file2 (SubFunc.js) into a document.onload event so that it will be executed when other files are loaded.

document.onload = function(){

   View.prototype.SubFunc = function() {
   }   
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.