Object

link Function Description
# extend Extends two objects, object functions.
# clone_deep Deep clones an object or array including all nested values.
# bind Binds a function to a context so it can be identified later if needed.
# flatten_obj Returns a new flattened version of an object and it's prototype(s) with its properties.
# object_props Returns an array of keys of all properties of an object and its prototype(s).
# prototypes Returns a flat array of of all nested prototypes of an object.


extend

Extends two objects, object functions

extend(Object|Function: base, Object|Function: extension): Object|Function
const Base = function(one, two)
{
    this.one = one;

    this.two = two;

    this.doSomething();
}
Base.prototype.doSomething = function()
{
    console.log(`${this.one} ${this.two}`);
}

const Extension = function(one, two)
{
    this.super(one, two);
}

const Extended = extend(Base, Extension);

// hello world!
let e = new Extended('hello', 'world!');
const Base = function(one, two)
{
    this.one = one;

    this.two = two;
}
Base.prototype.doSomething = function()
{
    console.log(`${this.one} ${this.two}`);
}

const Extension = function(one, two)
{
    this.one = one;

    this.two = two;
}

const Extended = extend(new Base('foo', 'bar'), new Extension('hello', 'world'));

// hello world!
Extended.doSomething();


clone_deep

Deep clones an object or array including all nested values.

clone_deep(Mixed: original): Mixed
let clone = clone_deep([ {foo: 'foo'} ]);

let clone = clone_deep({foo : () => console.log('hello world')});


bind

Binds a function to a context so it can be identified later if needed.

bind(Function: function, Mixed: context): Function
function foo() { console.log(this); }

let bound = bind(foo, 'bar');

// bar
bound();


flatten_obj

Returns a new flattened version of an object and it's prototype(s) with its properties.

flatten_obj(Object: object, ?deep: deep = false): Object
const WithProto = function(one, two) { }
WithProto.prototype.doSomething = function() { }

// { doSomething: function()... }
let flat = flatten_obj(new WithProto);


object_props

Returns an array of keys of all properties of an object and its prototype(s).

object_props(Object: object, ?deep: deep = false): Array
const WithProto = function(one, two) { this.foo = 'bar' }
WithProto.prototype.doSomething = function() { }

// [ 'foo', 'doSomething' ]
let props = object_props(new WithProto);


prototypes

Returns a flat array of of all nested prototypes of an object.

prototypes(Object: object): Array
const WithProto = function(one, two) { this.foo = 'bar' }
WithProto.prototype.doSomething = function() { }

// { foo: 'bar', doSomething: function()... }
let protos = prototypes(new WithProto);