Let\'s say I have this code (fiddle) intended to memoize modules:
var chat = {
// Create this closure to contain the cached modules
module: function() {
console.log('in module:', name);
You are logging name
before you ever declare it. So it's using window.name instead.
… = function() {
// …
console.log('in module:', name); // <---------- "in return: result"
return function(name) {…};
}();
You see, in the scope of that immediately-executed anonymous function expression, there is no variable "name
". Therefore, the global variable window.name will be used - it's value seems to be "result"
in your case (the jsfiddle target iframe's name) - try the unwrapped page, it will log an empty string.
Just for reference... "result" in this example, is the name (or better say the ID) of the lower right window (div/iframe) in JsFiddle...
So as @Rocket & @Bergi already says... you are getting the "window.name"