4

I have two js files. I am using namespaces within my js files. Here is what first JS files looks like:

(function(common, undefined) {
    "use strict";

    common.FunctionOne = function(){
        //do something
    };

}(window.common = window.common || {}));

The second js file looks like this:

(function(processing, undefined) {
    "use strict";

    processing.FunctionTwo = function(){
         common.FunctionOne()
    };

}(window.processing = window.processing || {}));

On my HTML page I have included the first js first and second one later (through tags). I am getting an error "Unable to get property 'FunctionOne' of undefined or null reference" in IE8 only. It works fine for other browsers.

I am not sure, but it looks like some namespace issue. Looks like IE8 is not recognizing the function that has been defined in the first js file.

Any thoughts?

Thanks.

levi
  • 23,693
  • 18
  • 59
  • 73
Blueboye
  • 1,374
  • 4
  • 24
  • 49
  • by "tags" are you referring to inline JS tags or external JS scripts? – levi Mar 21 '14 at 16:37
  • I tested this out in IE8 console (Win 7) on browserstack, changing FunctionOne to console out "hey friend," and it worked fine on processing.FunctionTwo(). Maybe it has something to do with the way you're including them in IE8, because it's not a namespacing issue – Nick Jurista Mar 21 '14 at 16:38
  • @levi I am including them through – Blueboye Mar 21 '14 at 17:39
  • How do you run your page: just double-click on a html-page or you have a local web-server (like IIS, Apache, etc)? – Kiril May 23 '14 at 17:37

1 Answers1

-1

hi I try to reproduce the error link to jsfiddle

(function(common, undefined) {
    "use strict";

    common.FunctionOne = function(){
        //do something
      $("#one").html("Hi you");
    };

}(window.common = window.common || {}));

(function(processing, undefined) {
    "use strict";

    processing.FunctionTwo = function(){
         common.FunctionOne();
    };

}(window.processing = window.processing || {}));
window.processing.FunctionTwo();

no files just one js with the two modules and it seems to work, try to open the fiddle, the first thing to know is ¿is the code itself failing?

if it works ok, we can try to make sure, ¿is the same window object in both cases? if an iframe is present you can be setting the code in the wrong window object

you can try adding a debugger; line in the second function and form the console look at window object and see what propierties it have