28 April, 2009

Essential JavaScript functions.

2009/07/22 Update:
Added Object.keys. Removed String.prototype.*, alert, and waitUntil.
"use strict";
if (typeof Object.create !== "function") {
    Object.create = function (o) {
        function F() {}
        F.prototype = o;
        return new F();
    };
}
if (typeof Object.keys !== "function") {
    Object.keys = function (obj) {
        var name, output = [];
        for (name in obj) {
            if (Object.prototype.hasOwnProperty.call(obj, name)) {
                output.push(name);
            }
        }
        return output;
    };
}

The above are functions I have found indispensable or extremely useful in my programming. They are listed here for convenience.

Object.create

String.prototype
window.alert
window.waitUntil

[LINK] The source code.
[LINK] The unit tests.

No comments:

Post a Comment