Rhinoでデータ構造を定義 その2

あんまりよくないかも…


lib.js

Object.prototype.to_m = function() {
var map = new java.util.HashMap();

for(var i in this) {
if(this[i] != arguments.callee) {
map.put(i, this[i]);
}
}

return map;
}

Array.prototype.to_l = function() {
var list = new java.util.ArrayList();

for(var i=0; i


本体

#!/usr/bin/env rhino
load('lib.js');

o = {
a:[
1,
2,
{x:'X', y:'Y'}.to_m(),
[
'zzz',
'yyy',
'xxx'
].to_l(),
'P'
].to_l(),
b:'B',
c:[1, 2, 3].to_a()
}.to_m();

print(o);