JSFiddle - React, Tailwind, and code Playground

by gianlucaguarini

HTML

<script src="http://underscorejs.org/underscore-min.js"></script>
<script src="http://backbonejs.org/backbone-min.js"></script>
<script src="https://getfirebug.com/firebug-lite.js"></script>

JavaScript

/*
*
* Parent class containing some methods and properties that must be inherited  
*
*/

var ParentClass = Backbone.Model.extend({
  initialize: function() {
    this.set('name','Dear');
  },
  say_hello: function ( ) {
    // property set only on the child
    console.log(this.get('greeting'));
  }
});

/*
*
* Child class extending the ParentClass 
*
*/

var ChildClass = ParentClass.extend({
  initialize: function () {
    this.constructor.__super__.initialize.apply(this);
    this.set('greeting','Hello!');
    // inherited method
    this.say_hello();
    // inherited property
    console.log(this.get('name'));
    // property set later once the class gets instanced
    console.log(this.get('surname'));
  }
});

new ChildClass({
    surname:'Friends'
});