Objects literal and 'this' in submodule pattern
问题 Im working in a sub-module pattern code. Want to create sub-modules with objects literals, the problem is this for the objects inside the sub-module is MODULE and not my object literal. Any idea? var MODULE.sub = (function () { var myObject = { key: value, method: function () { this.key // this = MODULE and not MyObject... :( } }; return myObject.method; }(MODULE)); 回答1: This works for me: var MODULE = MODULE || {}; MODULE.sub = (function () { return { myObject : { key : 10, method : function