Object

The Object unit in RightJS has some pretty much standard additional methods, which provide frequently used functionalities to process objects.

Methods

clone, each, empty, keys, merge, only, toQueryString, values, without

top ↑clone

Object.clone(Object obj) -> Object new

Description

A simple object cloning method

NOTE: this method does not perform a recursive cloning!

Example

var obj1 = {a:1};
var obj2 = Object.clone(obj1);

obj1 !== obj2;

top ↑each

Object.each(Object object, Function callback, Object scope) -> Object object

Description

Calls the callback function on every key-value pairs out of the given object

Example

var hash = {a: 1, b:2, c: 3};
var data = [];

Object.each(hash, function(key, value) {
keys.push(key + ':' + value);
});

data; // -> ['a:1', 'b:2', 'c:3']

top ↑empty

Object.empty(Object object) -> boolean

Description

Checks if the object has any key-value pairs in it.

Example

Object.empty({'a':1}) // -> false
Object.empty({}) // -> true

top ↑keys

Object.keys(Object object) -> Array keys

Description

Collects the object keys into an array.

Example

Object.keys({'a':1, 'b':2, 'c':3})

// -> ['a', 'b', 'c']

top ↑merge

Object.merge(Object o1, Object o2[, objects..]) -> Object new

Description

Creates a new object that contains all the key-value pairs of the given objects.

NOTE: this method performs a deep merge of objects!

Example

Object.merge({'a': 1, 'b': 2}, {'c': 3});

// -> {'a': 1, 'b': 2, 'c': 3}

top ↑only

Object.only(Object object, String key[, keys...]) -> Object new

Description

Creates a copy of the object with only the specified key-value paris in it.

Example

var object = {'a': 1, 'b': 2, 'c': 3};
Object.only(object, 'b', 'c');

// -> {'b': 2, 'c': 3}

top ↑toQueryString

Object.toQueryString(Object object) -> String

Description

Converts the object into a URL options string

Example

Object.toQueryString({a:'a', b:'b', c:'%#?'}));

// -> 'a=a&b=b&c=%25%23%3F'

top ↑values

Object.values(Object object) -> Array values

Description

Collects the object values into an array.

Example

Object.values({'a':1, 'b':2, 'c':3})

// -> [1, 2, 3]

top ↑without

Object.without(Object object, String key[, keys..]) -> Object new

Description

Creates a copy of the object without the specified key-value pairs in it.

Example

var object = {'a': 1, 'b': 2, 'c': 3};
Object.without(object, 'b');

// -> {'a': 1, 'c': 3}