function bindEvents(obj) {
    try {
        for (var k in obj) {
            if ((obj.hasOwnProperty(k) || obj.__proto__.hasOwnProperty(k))
                && typeof obj[k] == 'function'
                && k.length > 2
                && k.startsWith('on')
                && k[2].charCodeAt(0) >= 65
                && k[2].charCodeAt(0) <= 90) {
                obj[k] = obj[k].bind(obj);
            }
        }
    } catch (e) {
        console.error(e);
    }
    return obj;
}

function isObject(o) {
    return Object.prototype.toString.call(o) === '[object Object]';
}

function isArray(a) {
    return Object.prototype.toString.call(a) === '[object Array]';
}

function extend(dst, src) {
    if (typeof dst !== 'object') {
        return console.error('extend: dst is not an object');
    }
    if (typeof src !== 'object') {
        return console.error('extend: src is not an object');
    }
    for (var key in src) {
        dst[key] = src[key];
    }
    return dst;
}

function timestamp() {
    return Math.floor(Date.now() / 1000)
}

function stackTrace(split) {
    if (split === undefined) {
        split = true;
    }
    try {
        o.lo.lo += 0;
    } catch(e) {
        if (e.stack) {
            var stack = split ? e.stack.split('\n') : e.stack;
            stack.shift();
            stack.shift();
            return stack.join('\n');
        }
    }
    return null;
}

function escape(str) {
    var pre = document.createElement('pre');
    var text = document.createTextNode(str);
    pre.appendChild(text);
    return pre.innerHTML;
}

function parseUrl(uri) {
    var parser = document.createElement('a');
    parser.href = uri;

    return {
        protocol: parser.protocol, // => "http:"
        host: parser.host,         // => "example.com:3000"
        hostname: parser.hostname, // => "example.com"
        port: parser.port,         // => "3000"
        pathname: parser.pathname, // => "/pathname/"
        hash: parser.hash,         // => "#hash"
        search: parser.search,     // => "?search=test"
        origin: parser.origin,     // => "http://example.com:3000"
        path: (parser.pathname || '') + (parser.search || '')
    }
}

function once(fn, context) {
    var result;
    return function() {
        if (fn) {
            result = fn.apply(context || this, arguments);
            fn = null;
        }
        return result;
    };
}

function throttle(func, wait) {
    var timeout = null;
    var lastFunc;
    var lastRan;

    return function() {
        var context = this;
        var args = arguments;
        if (!lastRan) {
            func.apply(context, args);
            lastRan = Date.now();
        } else {
            clearTimeout(lastFunc);
            lastFunc = setTimeout(function() {
                if ((Date.now() - lastRan) >= wait) {
                    func.apply(context, args);
                    lastRan = Date.now();
                }
            }, wait - (Date.now() - lastRan));
        }
    };
}

function toCamelCase(s) {
    return s.split('-').map(function(word, index) {
        return index === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1);
    }).join('');
}

function sprintf() {
    var args = arguments,
        format = args[0],
        i = 1;
    return format.replace(/%(\d+)?([%s])/g, function(match, number, type) {
        if (type === "%") {
            return "%";
        }
        var index = number ? parseInt(number, 10) : i++;
        if (index >= args.length) {
            return match;
        }
        return args[index];
    });
}