Flipkart interview question

Q: Write poly-fill for Object.create?

Interview Answer

Anonymous

26 June 2017

if(typeof Object.create !== "function"){ Object.create = function(proto, properties){ if( (proto === null || typeof proto === "object" || typeof proto === "function")){ throw TypeError("Proto must be Object."); } var tmp = new Object(); tmp.__proto__ = proto; Object.defineProperty(tmp, properties); return tmp ; }; }

1