Javascript inheritance implementation question <p>In his sitepoint article about <a href="http://www.sitepoint.com/blogs/2006/01/17/javascript-inheritance/" rel="nofollow noreferrer" title="javascript inheritance">javascript inheritance</a>, Harry Fuecks explains a way of implementing inheritance as follows:</p> <pre><code> function copyPrototype(descendant, parent) { var sConstructor = parent.toString(); var aMatch = sConstructor.match( /\s*function (.*)\(/ ); if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; } for (var m in parent.prototype) { descendant.prototype[m] = parent.prototype[m]; } }; </code></pre> <p>While I understand his code, one question comes to mind - why not remove the for loop and simply do this:</p> <pre><code> function copyPrototype(descendant, parent) { var sConstructor = parent.toString(); var aMatch = sConstructor.match( /\s*function (.*)\(/ ); if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; } descendant.prototype = parent.prototype; }; </code></pre> <p>Thanks.</p>