$H().set('this', anotherHash) Unexpected Results

2 views
Skip to first unread message

Matt

unread,
Nov 5, 2009, 9:11:28 AM11/5/09
to Prototype & script.aculo.us
I believe I've tried this enough to say with certainty that using a
hash constructor followed immediately by the set() method does not
work, properly at least. In fact, it does add the value to the hash,
but not under any key, just directly off the main tree without a key.
I think this behavior should either be stopped or fixed (unless I'm
missing something).

var anotherHash = $H(a:'apple', b:'banana')
var newHash = $H().set('this', anotherHash)

Expected result...
// -> #<Hash:{'this':{'a':'apple', 'b':'banana'}}>
Actual result...
// -> #<Hash:{'a':'apple', 'b':'banana'}>

Using "new Hash().set()" of course has the same results.

The workaround for me was to make a function to create my hashes on
one line.

newHash(key, value) {
var h = new Hash()
h.set(key, value)
return h
}

Note how if you combine ANY of those three lines of code, you'll get
the broken hash. Interesting?
Reply all
Reply to author
Forward
0 new messages