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
- Host: GitHub
- URL: https://github.com/xotic750/object-create-x
- Owner: Xotic750
- License: mit
- Created: 2017-04-02T11:28:25.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T21:54:50.000Z (over 2 years ago)
- Last Synced: 2025-02-20T17:07:25.708Z (4 months ago)
- Topics: browser, create, ecmascript, nodejs, object
- Language: JavaScript
- Size: 3.06 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 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.'
```