Calling a Javascript member function of an object named in a variable

后端 未结 2 674
日久生厌
日久生厌 2021-01-28 10:19

I have the following so-called Revealing Module Pattern and I want to call the function a inside function b using a variable. How can

2条回答
  •  伪装坚强ぢ
    2021-01-28 10:48

    foo = function() {
        var inner = {
          a : function() {
          }
        };
    
        b = function() {
            memberName = 'a';
            // Call a() using value stored in variable `memberName`.
            inner[memberName]();
        }
    
        return {b: b};
    }();
    

提交回复
热议问题