The Javascript Object create() method creates a new object with the specified prototype object and properties.
Syntax:
Object.create(prototype[, propertiesObj]
Parameters: prototype: It represents the target object. It is a required parameter. propertiesObj: It represents enumerable properties that will be added to a newly created object. It is an optional parameter.
Return: A new object with the specified prototype object and properties.
Example:
<!DOCTYPE html> <html> <body> <script> function jewels() { this.name = 'DIAMOND'; } function gems() { jewels.call(this) } gems.prototype = Object.create(jewels.prototype); const select = new gems(); document.write(select.name); </script> </body> </html>
Please follow and like us: