Java的な発想

すべてのオブジェクトをキーにできるハッシュの様なもの - IT戦記
こんなんじゃダメかな。

function Dictionary() {
    this.initialize.apply(this, arguments);
}

Dictionary.prototype = {
    initialize: function() {
        this.hash = {};
    },
    put: function(k, v) {
        var key = [typeof k, k];
        this.hash[key] = v;
    },
    get: function(k) {
        var key = [typeof k, k];
        return this.hash[key];
    }
};



var dict = new Dictionary;

dict.put(1, 2)
dict.put('1', 3)

var f = function() { hoge };
var g = function() { fuga };

dict.put(f, 4)
dict.put(g, 5)

alert("dict.get( 1 )=[" + dict.get( 1 ) + "]"); // => 2
alert("dict.get('1')=[" + dict.get('1') + "]"); // => 3
alert("dict.get( f )=[" + dict.get( f ) + "]"); // => 4
alert("dict.get( g )=[" + dict.get( g ) + "]"); // => 5