Pot.Struct.tuple

{Object} Pot.Struct.tuple ({Array} items [, {Function} callback [, {*} defaultType]])

Pot.js で利用可能。 PotLite.js では利用できません。

items() 形式からオブジェクトに変換します。

Pot.items() 形式の配列から、オブジェクトに変換して返します。
引数 items は、対象の配列を指定します。
引数 callback は、任意に変換する際のコールバック関数を指定できます。
引数 defaultType は、任意に変換する型を指定できます。デフォルトはオブジェクトです。

Pot.globalize() が適応されている場合、Pot.tuple() が tuple() で実行できます。

items() 形式から変換されたオブジェクトが返ります。

var array = [['foo', 1], ['bar', 2], ['baz', 3]];
Pot.debug(Pot.tuple(array)); // {foo: 1, bar: 2, baz: 3}
var array = [['foo', 1, 'bar', 2], {baz: 3}, ['A', 4, 'B']];
Pot.debug(Pot.tuple(array)); // {foo: 1, bar: 2, baz: 3, A: 4, B: (void 0)}
// Callback function usage:
var array = [['A', 1], ['B', 2], ['C', 3]];
var func = function(key, val) {
  return ['[' + key + ']', '{' + val + '}'];
};
Pot.debug(Pot.tuple(array, func));
// {'[A]': '{1}', '[B]': '{2}', '[C]': '{3}'}
// Example to specify the type of result:
var array = [['prototype', 1], ['__iterator__', 2], ['__proto__', 3]];
Pot.debug(Pot.tuple(array, new Pot.Hash()).toJSON());
// {"prototype": 1, "__iterator__": 2, "__proto__": 3}
// Example to specify the type of result
//   (enables Array, Object, Pot.Hash etc.):
var array = [['A', 1], ['B', 2], ['C', 3]];
var func = function(key, val) {
  return '(' + key + ':' + val + ')';
};
Pot.debug(Pot.tuple(array, func, []));
// ['(A:1)', '(B:2)', '(C:3)']