Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some time ago, I looked at several object systems for JS and even implemented a few of my own, eg <a href="https://bitbucket.org/cggaertner/js-hacks/src/master/class.js" rel="nofollow noreferrer">class.js</a> (<a href="https://bitbucket.org/cggaertner/js-hacks/src/master/class5.js" rel="nofollow noreferrer">ES5 version</a>) and <a href="https://bitbucket.org/cggaertner/js-hacks/src/master/proto.js" rel="nofollow noreferrer">proto.js</a>.</p> <p>The reason why I never used them: you'll end up writing the same amount of code. Case in point: Resig's Ninja-example (only added some whitespace):</p> <pre><code>var Person = Class.extend({ init: function(isDancing) { this.dancing = isDancing; }, dance: function() { return this.dancing; } }); var Ninja = Person.extend({ init: function() { this._super(false); }, swingSword: function() { return true; } }); </code></pre> <p>19 lines, 264 bytes.</p> <p>Standard JS with <code>Object.create()</code> (which is an ECMAScript 5 function, but for our purposes can be replaced by a custom ES3 <a href="https://bitbucket.org/cggaertner/js-hacks/src/master/clone.js" rel="nofollow noreferrer"><code>clone()</code></a> implementation):</p> <pre><code>function Person(isDancing) { this.dancing = isDancing; } Person.prototype.dance = function() { return this.dancing; }; function Ninja() { Person.call(this, false); } Ninja.prototype = Object.create(Person.prototype); Ninja.prototype.swingSword = function() { return true; }; </code></pre> <p>17 lines, 282 bytes. Imo, the extra bytes are not really woth the added complexity of a seperate object system. It's easy enough to make the standard example shorter by adding some custom functions, but again: it's not realy worth it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload