Return to Snippet

Revision: 15047
at June 22, 2009 10:58 by iTony


Updated Code
function typeOf(value) {
    var s = typeof value;
    if (s === 'object') {
        if (value) {
            if (value instanceof Array) {
                s = 'array';
            }
        } else {
            s = 'null';
        }
    }
    return s;
}

String.prototype.supplant = function (o) {
    return this.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return typeof r === 'string' || typeof r === 'number' ? r : a;
        }
    );
};

String.prototype.trim = function () {
    return this.replace(/^\s+|\s+$/g, "");
};

Revision: 15046
at June 22, 2009 10:54 by iTony


Initial Code
function typeOf(value) {
    var s = typeof value;
    if (s === 'object') {
        if (value) {
            if (value instanceof Array) {
                s = 'array';
            }
        } else {
            s = 'null';
        }
    }
    return s;
}

Initial URL
http://javascript.crockford.com/remedial.html

Initial Description


Initial Title
Remedial Javascript Functionalities

Initial Tags
javascript

Initial Language
JavaScript