usage of Object.Create

Apr 11 2018 4:45 AM
Hi people ,
 
var shape = function() {}
shape.prototype.draw = function () {
document.write("I am shape
");
}
var circle = function () { }
circle.prototype = Object.create(shape.prototype);
 
or
 
circle.prototype = Object.create(shape);
 
For inheritance, we are usually using "Object.create(shape.prototype)" .
 
Not able to achieve the inheritance if we use Object.create(shape);
 
When i entered in browser debugger.
 
Object.create(shape) returns ,
Function {}__proto__: ƒ ()arguments: nullcaller: nulllength: 0name: "shape"prototype: {draw: ƒ, constructor: ƒ}__proto__: ƒ ()apply: ƒ apply()arguments: (...)bind: ƒ bind()call: ƒ call()caller: (...)constructor: ƒ Function()length: 0name: ""toString: ƒ toString()Symbol(Symbol.hasInstance): ƒ [Symbol.hasInstance]()get arguments: ƒ ()set arguments: ƒ ()get caller: ƒ ()set caller: ƒ ()__proto__: Object[[FunctionLocation]]: <unknown>[[Scopes]]: Scopes[0][[FunctionLocation]]: polymorshipsm.html:10[[Scopes]]: Scopes[1]
Object.create(shape.prototype) retruns
 
shape {}
 
What is difference between Object.create(shape.prototype) and Object.create(shape)

Answers (3)