Skip to content

Instantly share code, notes, and snippets.

@creationix
creationix / class.js
Created August 18, 2010 23:48
Port of my proto library, but doesn't mess with Object.prototype
// This is my proto library but without changing Object.prototype
// Then only sub-objects of Class have the special properties.
var Class = module.exports = Object.create(Object.prototype, {
// Implements a forEach much like the one for Array.prototype.forEach, but for
// any object.
forEach: {value: function forEach(callback, thisObject) {
var keys = Object.keys(this);
var length = keys.length;
for (var i = 0; i < length; i++) {
var key = keys[i];