0.0.2 • Published 11 years ago

tobject v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
11 years ago

TObject

Objects > Constructors

Usage

TObject provides simple inheritance with the use of traditional constructors.

Inspired by the Type.new blog post, I wrapped up this functionality in a tiny little lib. Basic usage:

var Button = TObject.extend({
  // className:'Button',
  text:'button text',
  color:'red',
  constructor: function (el) {
    console.log('Button');
    this.el = el;
    this.addEvents();
  },
  addEvents: function () {
  this.onClick();
  },
  onClick: function () {
      console.log('adding button event');
  } ,
    statics:{
        done:function(){
            console.log('button done');
        }
    }
});

var EvilButton = Button.extend({
  // className:'EvilButton',
color:'green',
  constructor: function () {
    console.log('EvilButton');
    this.callParent( arguments); // call `super`
  },

 //  onClick: function () {
 // this.callParent();
 //   console.log('adding evilbutton event');
 //  }

});

var BackButton = EvilButton.extend({
  // className:'BackButton',
color:'black',
  constructor: function () {
    console.log('BackButton');
    this.callParent( arguments); // call `super`
  },

  onClick: function () {
 this.callParent();
   console.log('adding evilbutton event');
  },
    statics:{
        done:function(){
            console.log('backbutton done');
            this.callParent();
        } ,

        create:function(){
           return new this;
        }
    }

});

var ZoomButton = BackButton.extend({
    constructor: function () {
        this.$$class.done();
    }
});

console.log('call static method');
ZoomButton.done();
ZoomButton.create();

console.log('new object');
var mybtn =new  ZoomButton('the EvilButton');