Name | Modified | Size | Downloads / Week |
---|---|---|---|
LICENCE | 2012-04-06 | 31.8 kB | |
README | 2011-05-21 | 1.9 kB | |
js-pseudo-class-v1.0.js | 2011-05-21 | 2.7 kB | |
Totals: 3 Items | 36.5 kB | 0 |
JavaScript Pseudo-Class Copyright (c) 2009-2011 James Watts (SOLFENIX) http://www.solfenix.com This is FREE software, licensed under the GPL http://www.gnu.org/licenses/gpl.html This pseudo-class for JavaScript lets you create, extend and inherit objects as classes. This allows you to build new objects from other instances, that can mutate and change their state or behaviour at runtime. Example: function Person( name, age, gender ) { this.Construct = function() { alert( 'New person created!' ); }; this.name = name || 'unknown'; this.age = age || 0; this.gender = gender || 'male'; this.getAge = function() { alert( this.name + ' is ' + this.age + ' years old!' ); }; this.setAge = function( age ) { this.age = age; }; } function James() { this.job = 'programmer'; } function Snow() { this.Construct = function() { this.gender = 'female'; }; this.job = 'beautition'; } function Mark( name ) { this.name = name; this.child = true; } function Philip() { this.Construct = function() { this.Inherit( Person, 'Philip', 47 ); this.age++; this.getAge(); }; this.inverse = true; } // extends Person with James var james = new Class( Person, 'James', 25 ).Extend( James ); // same as above, but longer var snow = new Class().Extend( Person, 'Snow', 35 ).Extend( Snow ); // executes the Construct of Parent, which is Person snow.Super(); // inherits current state from an instance of Snow var mark1 = snow.Extend( Mark, 'Mark' ); // overwrite mark's values with snow's var mark2 = new Class( Mark, 'Mark' ).Inherit( snow ); // mark3 extends from snow's default state var mark3 = new Class( Person, 'Snow', 35 ).Extend( Snow ).Extend( Mark, 'Mark' ); // inverse instantiation (see Philip.Construct) var philip = new Class( Philip );