<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 28, 2012, at 12:28 AM, Herby Vojčík wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>The proposal for <| cites these usage examples:<br><br>- Setting the prototype of a function to something other than Function.prototype<br><br>    let f = EnhancedFunctionPrototype <| function () {}<br><br>- Parrallel constructor/instance prototype chains<br><br>    let superclass = function () {};<br>    //define a constructor method<br>    superclass.new = function () {return (new this()).initialize()};<br>    //define a instance method<br>    superclass.prototype.initialize = function () {return this};<br>    let subclass = superclass <| function () {};<br>    ...<br><br>Question: When RHS is function expression, does it distinguish if LHS is function to select one of the (different) behaviours from above?<br></div></blockquote><div><br></div><div>from the proposal: "If the LHS operand has a property named <code>prototype</code> and the RHS operand is a function expression then the [[Prototype]] of the function object is set to the  LHS object and the <code>prototype</code> property of the new function is set to a new object whose [[Prototype]] is the value of the LHS’s <code>prototype</code> property. Here’s a picture of what happens in this case: <a href="http://wiki.ecmascript.org/lib/exe/fetch.php?id=harmony%3Aproto_operator&cache=cache&media=harmony:triangleupdate.pdf" class="urlextern" title="harmony:triangleupdate.pdf" style="background-image: url(/lib/images/fileicons/pdf.png)"> function "subclassing" UML diagram</a>"</div><div><br></div><div>In other words, it uses the value of <LHS>.prototype to set the [[Prototype]] of the new prototype object.  If no such property exists, [[Prototype]] of the prototype is set to its default value. </div><div><br></div><div>In all likelihood you would want EnhancedFunctionPrototype to be defined similarly to this  example from (<a href="https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp0.js">https://github.com/allenwb/ESnext-experiments/blob/master/ST80collections-exp0.js</a> ) of doing something different:</div><div><pre><div class="line" id="LC89">      <span class="c1">//define a non constructible superclass that provides some Smalltalk-like conventions</span></div><div class="line" id="LC90">   <span class="kr">const</span> <span class="nx">AbstractClass</span> <span class="o">=</span> <span class="nb">Function</span><span class="p">.</span><span class="nx">prototype</span> <span class="o"><|</span> <span class="p">{</span></div><div class="line" id="LC91">    <span class="nx">subclassResponsibility</span><span class="p">()</span> <span class="p">{</span><span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="o">+</span><span class="s2">" did not implemented an abstract method"</span><span class="p">)},</span></div><div class="line" id="LC92">       <span class="nx">shouldNotImplement</span><span class="p">()</span> <span class="p">{</span><span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="o">+</span><span class="s2">" should not implemented by "</span><span class="o">+</span><span class="k">this</span><span class="p">.</span><span class="nx">name</span><span class="p">)},</span></div><div class="line" id="LC93">        <span class="nx">name</span><span class="o">:</span> <span class="s2">"AbstractClass"</span><span class="p">,</span></div><div class="line" id="LC94">        <span class="nx">prototype</span><span class="o">:</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span> <span class="o"><|</span><span class="p">{</span></div><div class="line" id="LC95">            <span class="nx">get</span> <span class="kr">class</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">constructor</span><span class="p">},</span></div><div class="line" id="LC96">                <span class="nx">error</span><span class="p">(</span><span class="nx">message</span><span class="p">)</span> <span class="p">{</span><span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="nx">message</span><span class="p">)},</span></div><div class="line" id="LC97">         <span class="nx">subclassResponsibility</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="kr">class</span><span class="p">.</span><span class="nx">subclassResponsibility</span><span class="p">()},</span></div><div class="line" id="LC98">           <span class="nx">shouldNotImplement</span><span class="p">()</span> <span class="p">{</span><span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="kr">class</span><span class="p">.</span><span class="nx">shouldNotImplement</span><span class="p">()},</span></div><div class="line" id="LC99">           <span class="nx">errorSubscriptBounds</span><span class="p">(</span><span class="nx">index</span><span class="p">)</span> <span class="p">{</span><span class="k">this</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="s2">"subscript is out of bounds: "</span><span class="o">+</span><span class="nx">index</span><span class="p">)}</span></div><div class="line" id="LC100">         <span class="p">}</span></div><div class="line" id="LC101">     <span class="p">};</span></div></pre><div><br></div></div><div><br></div><div>Allen</div></div></body></html>