own-all

Turns inherited properties into owned properties.

Usage no npm install needed!

<script type="module">
  import ownAll from 'https://cdn.skypack.dev/own-all';
</script>

README

own-all

Turns inherited properties into owned properties.

Returns a new object. Does not modify the original.

Installation

Requires Node.js 6.0.0 or above.

npm i own-all

API

The module exports a single function.

Parameter

obj (object): The object which may possess owned and/or inherited properties.

Return Value

A new object which owns all of the properties, both owned and inherited, of obj.

Example

const ownAll = require('own-all')

Reflect.ownKeys(ownAll({a: 1})) /*
[
  'a',
  'constructor',
  '__defineGetter__',
  '__defineSetter__',
  'hasOwnProperty',
  '__lookupGetter__',
  '__lookupSetter__',
  'isPrototypeOf',
  'propertyIsEnumerable',
  'toString',
  'valueOf',
  '__proto__',
  'toLocaleString'
]
*/

// If you only want enumerable properties, use `Object.keys()` etc:
Object.keys(ownAll({a: 1})) // ['a']