<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    JFTR, I remember the previous the same discussion(s) and mentioned
    earlier the thing similar to this `Object.subclass`, though, just
    with providing an ability to specify the [[Class]] for
    `Object.create`. E.g. for a unclassified inheritance:<br>
    <br>
    let foo = Object.create(Array.prototype, "Array", {...});<br>
    <br>
    and for classified as well:<br>
    <br>
    <pre><div style="background-color: transparent;" class="line" id="LC83"><span class="c1">// create new constructor, objects of which</span></div><div style="background-color: transparent;" class="line" id="LC84"><span class="c1">// inherit from Array.prototype and are real</span></div><div style="background-color: transparent;" class="line" id="LC85"><span class="c1">// arrays, additionally pass prototype properties

</span></div><div style="background-color: transparent;" class="line" id="LC86"><span class="kd">var</span> <span class="nx">Foo</span> <span class="o">=</span> <span class="nx">Constructor</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span></div><div style="background-color: transparent;" class="line" id="LC87">  <span class="c1">
  // objects kind</span></div><div style="background-color: transparent;" class="line" id="LC88">  <span class="kr">class</span><span class="o">:</span> <span class="s2">"Array"</span><span class="p">,</span></div><div style="background-color: transparent;" class="line" id="LC89">  <span class="c1">
  // an initializer</span></div><div style="background-color: transparent;" class="line" id="LC90">  <span class="nx">constructor</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">Foo</span><span class="p">(</span><span class="nx">args</span><span class="p">)</span> <span class="p">{</span></div><div style="background-color: transparent;" class="line" id="LC91">    <span class="k">this</span><span class="p">.</span><span class="nx">push</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">args</span><span class="p">);</span></div><div style="background-color: transparent;" class="line" id="LC92">  <span class="p">},</span></div><div style="background-color: transparent;" class="line" id="LC93">  <span class="c1">
  // prototype properties (also may</span></div><div style="background-color: transparent;" class="line" id="LC94">  <span class="c1">// be added after "Foo" is created</span></div><div style="background-color: transparent;" class="line" id="LC95">  <span class="nx">prototype</span><span class="o">:</span> <span class="p">{</span></div><div style="background-color: transparent;" class="line" id="LC96">    <span class="nx">size</span><span class="o">:</span> <span class="p">{</span></div><div style="background-color: transparent;" class="line" id="LC97">      <span class="nx">get</span><span class="o">:</span> <span class="kd">function</span> <span class="nx">getSize</span><span class="p">()</span> <span class="p">{</span></div><div style="background-color: transparent;" class="line" id="LC98">        <span class="k">return</span> <span class="k">this</span><span clas
s="p">.</span><span class="nx">length</span><span class="p">;</span></div><div style="background-color: transparent;" class="line" id="LC99">      <span class="p">}</span></div><div style="background-color: transparent;" class="line" id="LC100">    <span class="p">}</span></div><div style="background-color: transparent;" class="line" id="LC101">  <span class="p">}

</span></div><div style="background-color: transparent;" class="line" id="LC102"><span class="p">});</span></div><div style="background-color: transparent;" class="line" id="LC103">
</div><div style="background-color: transparent;" class="line" id="LC104"><span class="kd">var</span> <span class="nx">foo</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Foo</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]);</span></div><div style="background-color: transparent;" class="line" id="LC105">
</div><div style="background-color: transparent;" class="line" id="LC106"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">foo</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span> <span class="c1">// 3</span></div><div style="background-color: transparent;" class="line" id="LC107">
</div><div style="background-color: transparent;" class="line" id="LC108"><span class="nx">foo</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">);</span></div><div style="background-color: transparent;" class="line" id="LC109">
</div><div style="background-color: transparent;" class="line" id="LC110"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">foo</span><span class="p">);</span> <span class="c1">// 1,2,3,4,5,6</span></div><div style="background-color: transparent;" class="line" id="LC111"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">foo</span><span class="p">.</span><span class="nx">length</span><span class="p">);</span> <span class="c1">// 6</span></div><div style="background-color: transparent;" class="line" id="LC112">
</div><div style="background-color: transparent;" class="line" id="LC113"><span class="nx">foo</span><span class="p">[</span><span class="mi">7</span><span class="p">]</span> <span class="o">=</span> <span class="mi">8</span><span class="p">;</span></div><div style="background-color: transparent;" class="line" id="LC114"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">foo</span><span class="p">);</span> <span class="c1">// 1,2,3,4,5,6,,8</span></div><div style="background-color: transparent;" class="line" id="LC115">
</div><div style="background-color: transparent;" class="line" id="LC116"><span class="nx">foo</span><span class="p">.</span><span class="nx">length</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span></div><div style="background-color: transparent;" class="line" id="LC117"><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">foo</span><span class="p">);</span> <span class="c1">// 1,2,3</span></div></pre>
    etc.<br>
    <br>
    Other examples:
<a class="moz-txt-link-freetext" href="https://github.com/DmitrySoshnikov/es-laboratory/blob/master/examples/create.js">https://github.com/DmitrySoshnikov/es-laboratory/blob/master/examples/create.js</a><br>
    <br>
    P.S.: yeah, mutable __proto__ is (was?) and interesting feature, but
    we tried to find its _real_ practical wide-spread application and
    couldn't. The same as we couldn't find the big practical rationale
    of the Python's __class__ from which __proto__ is borrowed. Yes,
    repeat, it's interesting from the _completely dynamic languages
    ideology_ (I like to show examples of first-class dynamic classes as
    oppose to second-class static classes), but if to start just analyze
    and try get again -- _real_ practical application, -- well, it's not
    so easy. Some internal lib hacks as mentioned by John cannot be
    considered as "practically widely spread". So the mutable __proto__
    (no matter in which name and view) can be standardized only if (1)
    no security issues, (2.1) practically needed or (2.2) just "a cool
    stuff of dynamic languages" with unfortunately small practical
    application.<br>
    <br>
    To avoid i-looping, Object.setPrototype(object, parent); is better
    than __proto__ of course.<br>
    <br>
    Dmitry.<br>
    <br>
    On 18.03.2011 22:36, David Bruant wrote:
    <blockquote cite="mid:4D83B42C.6010705@labri.fr" type="cite">
      <meta content="text/html; charset=ISO-8859-1"
        http-equiv="Content-Type">
      Le 18/03/2011 18:00, Oliver Hunt a écrit :
      <blockquote
        cite="mid:C746A8FD-5585-4CE1-BEB4-EBE9CB682280@apple.com"
        type="cite">
        <pre wrap="">I kind of dislike the proliferation of .create methods.  It's seems inelegant.  What if we had (use __proto__ for semantic description)

Object.subclass = function(constructor) {
    "use strict";
    function cons() {
        var result = constructor.apply(this, arguments);
        result.__proto__ = cons.prototype;
        return result;
    }
    cons.prototype = Object.create(constructor.prototype);
    return cons;
}
</pre>
      </blockquote>
      <br>
      Mike Shaver:<br>
      <blockquote type="cite">
        <pre>Andreas in IM that we hang it on the prototype chain, so that we get
it everywhere without repetitive specification.  How about:

Function.prototype.createDelegatingTo = function (obj)
{
  var o = new this; // really new-with-apply(arguments) here
   o.__proto__ = obj;
   return o;
}</pre>
      </blockquote>
      <br>
      <font size="-1"><big>One difference I see between Object.subclass
          and Function.prototype.createDelegatingTo is that the latter
          does not enforce anything on the prototype.<br>
          --<br>
          ( Array.createDelegatingTo({}) ) instanceof Array === false <br>
          <br>
          // while<br>
          <br>
          ( new </big></font><font size="-1"><big>Object.subclass(Array)

        </big></font><font size="-1"><big>) instanceof Array === true<br>
          --</big><br>
        <big><br>
          On the other hand, </big></font><font size="-1"><big>Function.prototype.createDelegatingTo

          is more expressive and </big></font><font size="-1"><big>Object.subclass

          can be implemented from it.</big></font><br>
      If methods such as Array.create are to be considered, this issue
      of enforcing Array.prototype will have to be addressed. I have
      personnally no strong conviction on one side or the other.<br>
      <br>
      David<br>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
es-discuss mailing list
<a class="moz-txt-link-abbreviated" href="mailto:es-discuss@mozilla.org">es-discuss@mozilla.org</a>
<a class="moz-txt-link-freetext" href="https://mail.mozilla.org/listinfo/es-discuss">https://mail.mozilla.org/listinfo/es-discuss</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>