Editing set __proto__ vs copy object This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) When you need to change the prototype of an object that already exists, how much faster is it to use __proto__ where supported instead of copying the object. Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) var A = function(a1, a2) { this.a1 = a1; this.a2 = a2; }; var B = function(b1, b2) { this.b1 = b1; this.b2 = b2; }; var AA = function(a1, a2, a3) { A.call(this, a1, a2); this.a3 = a3; }; // (new AA(1, 2, 3)) instanceof A === true AA.prototype = Object.create(A.prototype); var originalAA = new AA(1, 2, new B(new A(4, 5), new A(6, 7))); var serialized = JSON.stringify(originalAA); var deserialized = JSON.parse(serialized); Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code deserialized.__proto__ = AA.prototype; deserialized.a3.__proto__ = B.prototype; deserialized.a3.b1.__proto__ = A.prototype; deserialized.a3.b2.__proto__ = A.prototype; Test 2 Title Async (check if this is an asynchronous test) Code deserialized.a3.b1 = $.extend(Object.create(A.prototype), deserialized.a3.b1); deserialized.a3.b2 = $.extend(Object.create(A.prototype), deserialized.a3.b2); deserialized.a3 = $.extend(Object.create(B.prototype), deserialized.a3); deserialized = $.extend(Object.create(AA.prototype), deserialized); Test 3 Title Async (check if this is an asynchronous test) Code deserialized = new AA(deserialized.a1, deserialized.a2, new B(new A(deserialized.a3.b1.a1, deserialized.a3.b1.a2), new A(deserialized.a3.b2.a1, deserialized.a3.b2.a2)));