create-object

Portable Object.create that is not a shim and drops the verbose property descriptor syntax.

Usage no npm install needed!

<script type="module">
  import createObject from 'https://cdn.skypack.dev/create-object';
</script>

README

create-object

Portable Object.create that is not a shim and drops the verbose property descriptor syntax.

Build Status Code Climate js-standard-style

npm install create-object --save

You can also use Duo, Bower or download the files manually.

npm stats

npm NPM downloads Dependency Status

API Example

Create
var create = require('create-object')

var point = create({
  type: 'Point',
  coordinates: [-0.127758, 51.507351],
  valueOf: function () { return this.coordinates }
})

point
//=> {}

point.valueOf()
//=> [ -0.127758, 51.507351 ]
Create with properties
var create = require('create-object')

var geo = create({}, {
  coordinates: [-0.127758, 51.507351]
})

geo
//=> { coordinates: [ -0.127758, 51.507351 ] }

Features

  • True prototypal inheritance.
  • Your code does not need to bother with constructors or the new keyword.
  • Fields and methods on the prototype are non-enumerable.
  • Works in all JS engines (including old IEs like IE8).

Anti-Features

  • Does not shim/sham Object.create.
  • Ignores verbose ES5 property descriptor syntax.

API

create(prototype)

arguments
  • prototype: (Object) The object which should be the prototype of the newly-created object.
  • properties: (Object) Key-values which should be copied to the newly-created object.
returns
  • (Object) New object with the specified prototype object including any copied properties.

Reference

Alternatives

Contributing

SEE: contributing.md

Licenses

GitHub license