object-prototype

3.0.4 • Public • Published

object-prototype

A replacement prototype for Object.prototype with all the same functions.

npm build status js-standard-style

Installation

npm install object-prototype --save

Usage

const { create, ObjectPrototype } = require('object-prototype')
 
const obj1 = create()
const obj2 = {}
 
console.log(Object.prototype.isPrototypeOf(obj1)) // false
console.log(ObjectPrototype.isPrototypeOf(obj1)) // true
 
console.log(Object.prototype.isPrototypeOf(obj2)) // true
console.log(ObjectPrototype.isPrototypeOf(obj2)) // false
 
Object.prototype.foo = 42
 
console.log(obj1.foo) // undefined
console.log(obj2.foo) // 42

API

ObjectPrototype

The ObjectPrototype property exposed by this module is ment as a replacement to Object.prototype and has the following ECMAScript spec'd functions:

And the following functions which are considered deprecated according to the ECMAScript specification:

object = create()

The create function is a convenience function that returns a new object with ObjectPrototype as its prototype.

This is equivalent to writing Object.create(ObjectPrototype).

object = assign([...objects])

The assign function is a convenience function that returns a new object with all the same properties as the provided objects, but with ObjectPrototype as its prototype.

This is equivalent to writing Object.assign(Object.create(ObjectPrototype), ...objects).

FunctionPrototype

The FunctionPrototype property exposed by this module is ment as a replacement to Function.prototype and exposes the same properties.

function = safePrototypeFunction(function)

Given a function as the first argument, safePrototypeFunction will return another function which wraps the given function in a way so that it doesn't leak Object.prototype.

License

MIT

Package Sidebar

Install

npm i object-prototype

Weekly Downloads

3

Version

3.0.4

License

MIT

Unpacked Size

10.1 kB

Total Files

5

Last publish

Collaborators

  • watson