Assuming Code (javascript): if(!sys.require) { sys.require = function(filename) { return eval( sys.getFileContent('scripts/'+filename) ); }; }; Suppose, I have a module A in a.js: Code (javascript): function A() { this.field = 'Lorem Ipsum'; }; A.prototype.print = function() { sys.sendHtmlAll(this.field); } //sys.sendHtmlAll('hello from A'); (new A()) And I use it this way: Code (javascript): var A = sys.require('a.js') A.print(); But then script engine crashed with Code (text): TypeError: Result of expression 'A' [undefined] is not an object. And the wierd part is that if I uncomment sys.sendHtmlAll('hello from A');, it works perfectly. Calling anything from sys object somehow fixes everything. In another module another problem occurs: inside class method (again, assigned via function prototype) this somehow turns out to be global script object, not an instance of that class. Again, a call to sys fixes everything.
It also works if you have just Code (text): new A instead of wrapping it into braces... which really does not make any sense.
...Or if I add a semicolon after last function declaration. So it is parsed as { /* ... */ }() Damn...
That's why optional semicolons are a bad idea... After function statement there should be no semicolon. After function expression there should be. Assigning an anonymous or named function to prototype is expression even if it looks like statement.