2

Here is part of my code

Actual Code:

Top:

var NS = (function (global) 
    {

Middle:

var ViewH = 
{
    portfolio: function ( embeddedAml ) 
        {
        internals
        },

Bottom:

return {    
    ViewHPortfolio:    ViewH.portfolio,
};

})(window);

However, IE is reporting that var1 is undefined. I define it in the function parameter list and use it in the function. Not too sure what the interpreter is realy saying.

These functions worked until I moved them into a common object - Container

Also IE would not let me pass Container.func1 so I passed it to the HTML as ContainerFunc1.

Question is, how do I get the interpreter to recognize the variables var1, var2...etc.

Thanks,

0

1 Answer 1

3

I think you're a victim of semicolon insertion.

Change this:

return
  {
  ContainerFunc1:   Container.func1
  ContainerFunc2:   Container.func2
  }

to this:

return {
  ContainerFunc1:   Container.func1
  ContainerFunc2:   Container.func2
  };

Also, I think this

Container 
  {
    func1 : function(var1){...do something with var1...}
    func2 : function(var1){}
  }

Should be this

var Container = {
    func1 : function(var1){...do something with var1...}
    func2 : function(var1){}
  };

Finally, be aware that when you do

return {
  ContainerFunc1:   Container.func1
  ContainerFunc2:   Container.func2
};

And you say

var resultObj = Top();
resultObj.ContainerFunc1(X);

even though this function—ContainerFunc1—points to Container.func1 the this inside the call will not be Container; this will be resultObj.

Finally, by convention functions that start with a capital letter in JavaScript are intended to be used as a constructor. To comport with this convention you should consider changing the name to top with a lowercase t.

Sign up to request clarification or add additional context in comments.

2 Comments

@stack.user.0 - you cannot do that. JS will put a semicolon after return. You need to say return { with the opening brace on the same line as return
You did not fix the var in front of Container

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.