Skip to content
Adds nice utilities to Object.prototype for JavaScript using Object.defineProperty
Latest commit 2e783fa Aug 13, 2010 @creationix Fix README
Failed to load latest commit information.
lib Add a mini test suite. Aug 13, 2010
README.markdown Fix README Aug 13, 2010
test.js Add a mini test suite. Aug 13, 2010



This simple js library adds four functions to Object.prototype. Since this only modifies global objects and doesn't export any structures, you don't need the return value when calling require('proto').


All functions added to Object.prototype are usable from any object in JavaScript.

Object.prototype.forEach(callback[, thisObject])

This is the most useful of the additions. It allows you to forEach over an Object instance's local properties and values just like you can already do with Array instances.

({name: "Tim", age: 28}).forEach(function (value, key) {
  console.log(key + " = " + JSON.stringify(value));
});[, thisObject])

This works like forEach, except returns an Array instance with the returned values of the function calls.

var pairs = ({name: "Tim", age: 28}).map(function (value, key) {
  return key + " = " + value;
// pairs is ["name = Tim", "age = 28"]

Creates a new version of the current object and calls it's initialize function if one exists with the same arguments passed to new.

var Rectangle = {
  initialize: function initialize(width, height) {
    this.width = width;
    this.height = height;
  get area() {
    return this.width * this.height;

var rect =, 4);


Sets the current object as the prototype to the passed in object and returns the new passed in object.

// Assuming the code from above
var Square = Rectangle.extend({
  initialize: function initialize(side) {
    this.width = side;
    this.height = side;
var square =;
Something went wrong with that request. Please try again.