Editing Nested Named Functions compared to Module Pattern This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Demonstrating the performance hit caused by nested functions and testing against module pattern. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script> (function() { // Nested function person = function(age) { function getNextAge() { return age + 1; } return getNextAge(); } // Non nested function inner function function getNextAge2(age) { return age + 1; } // Non nested function person2 = function(age) { return getNextAge2(age); } }()); // YUI style (http://www.yuiblog.com/blog/2007/06/12/module-pattern/) var myNamespace = myNamespace || {}; myNamespace.module1 = (function() { //"private" method: var getNextAge3 = function(age) { return age + 1; } return { person3: function(age) { return getNextAge3(age); } }; }()); // Adding New Functionality to the person4 // http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/ (function( person4, $, undefined ) { person4.Age = 0; //Public Method person4.getNextAge = function() { return person4.Age + 1; }; }( window.person4 = window.person4 || {}, {} )); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code person2(10); Test 2 Title Async (check if this is an asynchronous test) Code person(10); Test 3 Title Async (check if this is an asynchronous test) Code myNamespace.module1.person3(10); Test 4 Title Async (check if this is an asynchronous test) Code person4.Age = 10; person4.getNextAge()