Editing Nested Named Functions compared to Module Pattern without last 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, without certain 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 mySandwich(param1, param2, callback) { console.log('Started eating my sandwich.\n\nIt has: ' + param1 + ', ' + param2); var sth = "test"; callback(sth); } // Non nested function inner function function mycallback(sth) { console.log('Finished eating my sandwich.' + sth); } // 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 mySandwich('ham', 'cheese', mycallback); Test 2 Title Async (check if this is an asynchronous test) Code mySandwich('ham', 'cheese', function(sth) { console.log('Finished eating my sandwich.'+sth); }); Test 3 Title Async (check if this is an asynchronous test) Code myNamespace.module1.person3(10);