3.1.2 • Published 5 years ago
object-create-x v3.1.2
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
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.'
3.1.2
5 years ago
3.1.1
5 years ago
3.1.0
5 years ago
3.0.16
5 years ago
3.0.15
5 years ago
3.0.14
5 years ago
3.0.13
5 years ago
3.0.12
5 years ago
3.0.11
5 years ago
3.0.10
5 years ago
3.0.9
5 years ago
3.0.8
5 years ago
3.0.7
5 years ago
3.0.6
5 years ago
3.0.5
5 years ago
3.0.4
5 years ago
3.0.3
5 years ago
3.0.2
5 years ago
3.0.1
5 years ago
3.0.0
5 years ago
2.1.0
7 years ago
2.0.0
7 years ago
1.2.0
7 years ago
1.1.0
7 years ago
1.0.0
7 years ago