An open API service indexing awesome lists of open source software.

https://github.com/xotic750/object-create-x

Sham for Object.create
https://github.com/xotic750/object-create-x

browser create ecmascript nodejs object

Last synced: 3 months ago
JSON representation

Sham for Object.create

Awesome Lists containing this project

README

        


Travis status


Dependency status


devDependency status


npm version


jsDelivr hits


bettercodehub score


Coverage Status

## object-create-x

Sham for Object.create

### `module.exports` ⇒ boolean

This method method creates a new object with the specified prototype object and properties.

**Kind**: Exported member
**Returns**: boolean - A new object with the specified prototype object and properties.
**Throws**:

- TypeError If the properties parameter isn't null or an object.

| Param | Type | Description |
| ------------ | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| prototype | \* | The object which should be the prototype of the newly-created object. |
| [properties] | \* | If specified and not undefined, an object whose enumerable own properties (that is, those properties defined upon itself and not enumerable properties along its prototype chain) specify property descriptors to be added to the newly-created object, with the corresponding property names. |

**Example**

```js
import create from 'object-create-x';

// Shape - superclass
function Shape() {
this.x = 0;
this.y = 0;
}

// superclass method
Shape.prototype.move = function(x, y) {
this.x += x;
this.y += y;
console.info('Shape moved.');
};

// Rectangle - subclass
function Rectangle() {
Shape.call(this); // call super constructor.
}

// subclass extends superclass
Rectangle.prototype = create(Shape.prototype);
Rectangle.prototype.constructor = Rectangle;

const rect = new Rectangle();

console.log('Is rect an instance of Rectangle?', rect instanceof Rectangle); // true
console.log('Is rect an instance of Shape?', rect instanceof Shape); // true
rect.move(1, 1); // Outputs, 'Shape moved.'
```