Extendable micro-lib demo.

Showing off Extendable. author(s): Irakli Gozalishvili

HTML

<script src="http://jeditoolkit.com/teleport/support/teleport/teleport.js"></script>

JavaScript

/* vim:set ts=2 sw=2 sts=2 expandtab */
/*jshint asi: true undef: true es5: true node: true devel: true
         forin: true latedef: false supernew: true */
/*global define: true */


define('demo', function(require, exports, module, undefined) {

'use strict';

var Extendable = require("https://github.com/Gozala/extendables/raw/v0.1.2/lib/extendables.js").Extendable

var Base = Extendable.extend({
  inherited: function inherited() {
    return "inherited property"
  },
  overridden: function overridden() {
    return "property to override"
  },
  // No supers by default, use prototype and be proud, but if you really want
  // super get one!
  _super: function _super() {
    return Object.getPrototypeOf(Object.getPrototypeOf(this))
  }
})
// Adding static method.
Base.implement = function implement(source) {
  // Going through each argument to copy properties from each source.
  Array.prototype.forEach.call(arguments, function(source) {
    // Going through each own property of the source to copy it.
    Object.getOwnPropertyNames(source).forEach(function(key) {
      // If property is already owned then skip it.
      if (Object.prototype.hasOwnProperty.call(this.prototype, key)) return null
      // Otherwise define property.
      Object.defineProperty(this.prototype, key,
                            Object.getOwnPropertyDescriptor(source, key))
    }, this)
  }, this)
}

var b1 = new Base
console.log(b1 instanceof Base)              // -> true
console.log(b1 instanceof Extendable)        // -> true
console.log(b1.inherited())                  // -> "inherited property"

var b2 = Base()                             // -> Works same as without `new`
console.log(b2 instanceof Base)             // -> true
console.log(b2 instanceof Extendable)       // -> true
console.log(b2.inherited())                 // -> "inherited property"


var Decedent = Base.extend({
  constructor: function Decedent(options) {
    this.name = options.name;
  },
  overridden: function...