Creates an object that inherits from the `prototype` object. If a `properties` object is given, its own enumerable string keyed properties are assigned to the created object.
function Shape() {
this.x = 0
this.y = 0
}
function Circle() {
Shape.call(this)
}
Circle.prototype = create(Shape.prototype, {
'constructor': Circle
})
const circle = new Circle
circle instanceof Circle
// => true
circle instanceof Shape
// => true
Name | Type | Attribute | Description |
---|---|---|---|
prototype | The object to inherit from. | ||
properties | The properties to assign to the object. |
{ "comment": "/**\r\n * Creates an object that inherits from the `prototype` object. If a\r\n * `properties` object is given, its own enumerable string keyed properties\r\n * are assigned to the created object.\r\n *\r\n * @since 2.3.0\r\n * @category Object\r\n * @param {Object} prototype The object to inherit from.\r\n * @param {Object} [properties] The properties to assign to the object.\r\n * @returns {Object} Returns the new object.\r\n * @example\r\n *\r\n * function Shape() {\r\n * this.x = 0\r\n * this.y = 0\r\n * }\r\n *\r\n * function Circle() {\r\n * Shape.call(this)\r\n * }\r\n *\r\n * Circle.prototype = create(Shape.prototype, {\r\n * 'constructor': Circle\r\n * })\r\n *\r\n * const circle = new Circle\r\n * circle instanceof Circle\r\n * // => true\r\n *\r\n * circle instanceof Shape\r\n * // => true\r\n */", "meta": { "range": [ 766, 987 ], "filename": "create.js", "lineno": 33, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100000952", "name": "create", "type": "FunctionDeclaration", "paramnames": [ "prototype", "properties" ] }, "vars": { "prototype": "create~prototype", "result": "create~result" } }, "description": "Creates an object that inherits from the `prototype` object. If a\r`properties` object is given, its own enumerable string keyed properties\rare assigned to the created object.", "since": "2.3.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Object", "value": "Object" } ], "params": [ { "type": { "names": [ "Object" ] }, "description": "The object to inherit from.", "name": "prototype" }, { "type": { "names": [ "Object" ] }, "optional": true, "description": "The properties to assign to the object.", "name": "properties" } ], "returns": [ { "type": { "names": [ "Object" ] }, "description": "Returns the new object." } ], "examples": [ "function Shape() {\r this.x = 0\r this.y = 0\r}\r\rfunction Circle() {\r Shape.call(this)\r}\r\rCircle.prototype = create(Shape.prototype, {\r 'constructor': Circle\r})\r\rconst circle = new Circle\rcircle instanceof Circle\r// => true\r\rcircle instanceof Shape\r// => true" ], "name": "create", "longname": "create", "kind": "function", "scope": "global", "___id": "T000002R000098", "___s": true, "filepath": "create.js" }