From 2a2a05bab3df9de9476d67590a0d8d7e3ce588b6 Mon Sep 17 00:00:00 2001 From: Kevin Dangoor Date: Tue, 11 Jan 2011 23:18:23 -0500 Subject: [PATCH] modules weren't being cached (so doing require("foo") twice would return two independent copies of the foo module, thus messing up any state stored in that module) the visible evidence of this is that commands (such as keyboard movements) could not be found --- demo/mini_require.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/demo/mini_require.js b/demo/mini_require.js index 150cdf8e..122ebbf9 100644 --- a/demo/mini_require.js +++ b/demo/mini_require.js @@ -14,6 +14,7 @@ function require(module, callback) { if (typeof module === 'string') { var payload = require.modules[module]; + var module_name = module; if (payload == null) { console.error('Missing module: ' + module); } @@ -26,6 +27,8 @@ function require(module, callback) { }; payload(require, exports, module); payload = exports; + // cache the resulting module object for next time + require.modules[module_name] = payload; } if (callback) {