object
The object function and related utilities handle object creation and manipulation.
Creation
object(obj)
Shallow copy an object.
var copy = object(original)
object(obj, another)
Combine two objects.
object({a: 1}, {b: 2}) // {a: 1, b: 2}
object({a: 1}, {a: 2}) // {a: 2}
object(obj, keys)
Select specific keys.
object({a: 1, b: 2, c: 3}, ["a", "c"]) // {a: 1, c: 3}
object(keys)
Create object from keys (values are true).
object(["a", "b", "c"]) // {a: true, b: true, c: true}
object(keys, value)
Create object from keys with specified value.
object(["a", "b"], 0) // {a: 0, b: 0}
object(keys, fn)
Create object from keys with computed values.
object(["a", "b", "c"], (k, i) => i) // {a: 0, b: 1, c: 2}
Prototypes
meme(prototype)
Create a new object with the given prototype.
var animal = {speak: function() { log.console("...") }}
var dog = meme(animal)
dog.speak = function() { log.console("woof") }
proto(obj)
Get an object's prototype.
var p = proto(dog) // animal
isa(obj, prototype)
Check if prototype is in the chain.
isa(dog, animal) // true
Serialization
splat(obj)
Flatten an object's prototype chain into a plain object. Only includes primitive types (numbers, text, booleans, arrays, objects).
var base = {x: 1}
var derived = meme(base)
derived.y = 2
splat(derived) // {x: 1, y: 2}
When sending objects between actors with $send, they are automatically splatted.
Key Iteration
var obj = {a: 1, b: 2, c: 3}
// Get all keys
var keys = array(obj) // ["a", "b", "c"]
// Iterate
for (var key in obj) {
log.console(key, obj[key])
}