Created
June 3, 2010 22:05
-
-
Save orlandov/424572 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Explanation: | |
| I was seeing some bizarre behaviour in a program I was developing. After | |
| fruitlessly debugging my code, I distilled the crazyness down to this. | |
| This script is full of WTF. Have a what the code is doing vs what the script | |
| is printing. | |
| Try out on node master@HEAD. Script seems to work up to v0.1.97 of node. | |
| Anything after that such as HEAD on master don't work on the platforms I | |
| tested (osx, solaris, linux). | |
| Solaris | |
| ------- | |
| node tag v0.1.94 - works | |
| node tag v0.1.97 - works | |
| node master - doesn't work | |
| OSX | |
| --- | |
| node tag v0.1.96 - works | |
| Linux | |
| ----- | |
| node v0.1.97 - works | |
| node master - doesn't work | |
| */ | |
| sys = require('sys'); | |
| puts = sys.puts; | |
| inspect = sys.inspect; | |
| globalHash = {}; | |
| Shazbot = function (args) { | |
| this.objectHash = {}; | |
| } | |
| Shazbot.prototype.myFunction = function() { | |
| // if you set this value to a non numeric value it works | |
| // var id = 'abcdefg'; // if we use this it will work | |
| var id = '22345678'; | |
| puts("objectHash:"+inspect(this.objectHash)); | |
| puts("globalHash:"+inspect(globalHash)); | |
| globalHash[id] = {}; | |
| puts("This will fail the second time we call this function: " + inspect(globalHash)); | |
| // Why does this fail??? globalHash[id] was just set above! | |
| globalHash[id]['foo'] = 'foo'; | |
| this.objectHash[id] = { }; | |
| this.objectHash[id]['foo'] = 'foo'; | |
| puts("\nThis should print { '" + id + "': { 'foo': 'foo' }\n"); | |
| puts("objectHash:"+inspect(this.objectHash)); | |
| puts("globalHash:"+inspect(globalHash)); | |
| } | |
| a = new Shazbot(); | |
| a.myFunction(); | |
| a.myFunction(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment