File: test

Recommend this page to a friend!
  Classes of Bradley Matusiak   Extend   test   Download  
File: test
Role: Example script
Content type: text/plain
Description: test file for extend.js
Class: Extend
Create new objects that extend other objects
Author: By
Last change:
Date: 12 years ago
Size: 2,107 bytes
 

Contents

Class file image Download
require("./extend.js"); function _SuperClass() { if (this.base) this.base(); this.testA = "test1"; console.log("SuperClass constructor"); } _SuperClass.prototype.t1 = function() { if (this.base) this.base(); console.log("t1"); }; var SuperClass = _SuperClass.extend(Array,_SuperClass); function _ClassT() { if (this.base) this.base(); this.testB = "test2"; console.log("Class constructor"); } _ClassT.prototype.t1 = function() { console.log("t2"); if (this.base) this.base(); }; var ClassT = SuperClass.extend(_ClassT); function _SubClass() { if (this.base) this.base(); this.testB = "test3"; console.log("SubClass constructor"); } _SubClass.prototype.t1 = function() { if (this.base) this.base(); console.log("t3"); }; var SubClass = ClassT.extend(_SubClass); //Following produces /* SuperClass constructor Class constructor SubClass constructor class init time took 11 milisec t2 t1 t3 */ var doneTime,startTime; startTime= new Date(); var testit = new SubClass(); doneTime = new Date(); console.log("class init time took ",doneTime - startTime, "milisec"); testit.t1(); console.log(testit); //{ testA: 'test1', testB: 'test3' } console.log(testit._this); //{ [Function: _SubClass] _parent: { [Function: _ClassT] _parent: { [Function: _SuperClass] _parent: [Object] } } } console.log(testit._this._parent); //{ [Function: _ClassT] _parent: { [Function: _SuperClass] _parent: { [Function: Function] _this: [Circular] } } } //Following produces /* _SubClass is not Function _SubClass is a Object _SubClass is not Date _SubClass is a Array _SubClass is not Boolean _SubClass is not String _SubClass is not RegExp _SubClass is not Number */ var Types = {Function:Function,Object:Object,Date:Date,Array:Array,Boolean:Boolean,String:String,RegExp:RegExp,Number:Number}; for(var i in Types){ console.log(testit._this.name+" is " +(testit instanceof Types[i] ? "a" :"not" )+" "+i); }