In the code for the Express module for Node.js I came across this line, setting inheritance for the server:
Server.prototype.__proto__ = connect.HTTPServer.prototype;
I'm not sure what this does - the MDC docs (https://developer.mozilla.org/en/JavaScript/Guide/Inheritance_Revisited#prototype_and_proto) seem to say that I could just do:
Server.prototype = connect.HTTPServer.prototype;
Indeed, I did this test:
var parent = function(){}
parent.prototype = {
test: function(){console.log('test')};
}
var child1 = function(){};
child1.prototype = parent.prototype;
var instance1 = new child1();
instance1.test(); // 'test'
var child2 = function(){};
child2.prototype.__proto__ = parent.prototype;
var instance2 = new child2();
instance2.test(); // 'test'
Looks to be the same? So yah, I'm wondering what setting object.prototype.__proto is for. Thanks!