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&2J!HCMbw@CJ+&4vL6JzzOUi$ruSzvZ
z?9|d
kF*w{SO%|9g@`M&|1CP)
zxau-_vNQ96
- ease.js is a Classical Object-Oriented framework for JavaScript, - intended to “ease” the transition into JavaScript from other - Object-Oriented languages. Features include: + ease.js is a Classical Object-Oriented framework for + JavaScript, intended to eliminate boilerplate code and + “ease” the transition into JavaScript from other Object-Oriented + languages. Features include:
-- ease.js is a framework, not a compiler. It may be used wherever - JavaScript may be used, including with other compilers/parsers. ease.js - also provides support for older, pre-ES5 environments by gracefully - degrading features (such as visibility support), but remaining - functionally consistent. + ease.js is a framework, not a compiler. It may be used wherever JavaScript may + be used, including with other compilers/parsers. ease.js also provides + support for older, pre-ES5 environments by gracefully degrading features (such + as visibility support), but remaining functionally consistent.
+ ++ Class definitions closely resemble the familiar syntax of languages like Java, + C++, C# and PHP. +
++ ++ +
+ Classes can be anonymous or named, the latter being more useful for debugging. + Since classes may be anonymous, constructors are styled after PHP: +
++ ++ +
+ Classes can be instantiated with or without the new keyword. Omission + aids in concise method chaining and the use of temporary classes. +
++ var inst = Foo( "John Doe" ); + var inst = new Foo( "John Doe" ); + + // temporary class + Foo( "John Doe" ).sayHello(); ++ + +
+ Classes can be extended to create subtypes. Like C++, methods are + not virtual by default. In Java terminology, all methods are + final by default. Multiple inheritance, like Java, is unsupported (see + Interfaces). +
++ ++ +
+ Alternatively, if creating an anonymous subtype, the supertype's + extend() method may be used. +
++ var SturdyCow = Cow.extend( { /*...*/ } ); ++ +
+ To prevent a class from being extended, FinalClass can be used. +
++ ++ + +
+ If a class contains abstract members, it must be declared as an + AbstractClass. Abstract methods must be overridden by subtypes and + are implicitly virtual. +
++ ++ + +
+ ease.js supports the Java concept of Interfaces, which act much like abstract + classes with no implementation. Each method is implicitly abstract. Properties + cannot be defined on interfaces. +
++ ++ +
+ Concrete classes may implement one or more interfaces. If a concrete class + does not provide a concrete implementation for every method defined on the + interface, it must be declared an AbstractClass. +
++ ++ +
+ Polymorphic methods may check whether a given object implements a certain + interface. +
++ ++ + +
+ All three common access modifiers — public, protected and private + — are supported, but enforced only in ECMAScript 5 and later + environments. +
++ ++
+ In the above example, the database connection remains encapsulated within + DatabaseRecord. Subtypes are able to query and escape strings and + external callers are able to retrieve a name for a given id. Attempting to + access a private or protected member externally will result in an error. + Attempting to access a private member from within a subtype will result in an + error. +
+ + ++ Static members are bound to the class itself, rather than a particular + instance. Constants are immutable static members (unlike languages like PHP, + they may use any access modifier). In order to support both + pre- and post-ECMAScript 5 environments, the syntax requires use of a static + accessor method — $(). +
++ ++ + + + diff --git a/scripts/ex/access-modifiers.js b/scripts/ex/access-modifiers.js new file mode 100644 index 0000000..54bf9a9 --- /dev/null +++ b/scripts/ex/access-modifiers.js @@ -0,0 +1,35 @@ +var DatabaseRecord = Class( 'DatabaseRecord', +{ + 'private _connection': null, + + + __construct: function( host, user, pass ) + { + this._connection = this._connect( host, user, pass ); + }, + + 'private _connect': function( host, user, pass ) + { + // (do connection stuff) + return { host: host }; + }, + + 'protected query': function( query ) + { + // perform query on this._connection, rather than exposing + // this._connection to subtypes + }, + + 'protected escapeString': function( field ) + { + return field.replace( "'", "\\'" ); + }, + + 'public getName': function( id ) + { + return this._query( + "SELECT name FROM users WHERE id = '" + + this._escapeString( id ) + "' LIMIT 1" + ); + }, +} ); diff --git a/scripts/ex/class-abstract.js b/scripts/ex/class-abstract.js new file mode 100644 index 0000000..3441c8b --- /dev/null +++ b/scripts/ex/class-abstract.js @@ -0,0 +1,23 @@ +var Database = AbstractClass( 'Database', +{ + 'public connect': function( user, pass ) + { + if ( !( this.authenticate( user, pass ) ) ) + { + throw Error( "Authentication failed." ); + } + }, + + // abstract methods define arguments as an array of strings + 'abstract protected authenticate': [ 'user', 'pass' ], +} ); + +var MongoDatabase = Class( 'MongoDatabase' ) + .extend( Database, +{ + // must implement each argument for Database.authenticate() + 'protected authenticate': function( user, pass ) + { + // ... + }, +} ); diff --git a/scripts/ex/class-anon.js b/scripts/ex/class-anon.js new file mode 100644 index 0000000..d16947b --- /dev/null +++ b/scripts/ex/class-anon.js @@ -0,0 +1,13 @@ +var Foo = Class( + 'private _name': '', + + __construct: function( name ) + { + this._name = ''+( name ); + }, + + 'public sayHello': function() + { + return this._name + " says 'Hello!'"; + }, +); diff --git a/scripts/ex/class-extend.js b/scripts/ex/class-extend.js new file mode 100644 index 0000000..9914781 --- /dev/null +++ b/scripts/ex/class-extend.js @@ -0,0 +1,16 @@ +var Cow = Class( 'Cow', +{ + 'virtual public tip': function() + { + return "Omph."; + }, +} ); + +var SturdyCow = Class( 'SturdyCow' ) + .extend( Cow, +{ + 'override public tip': function() + { + return "Moo."; + }, +} ); diff --git a/scripts/ex/class-final.js b/scripts/ex/class-final.js new file mode 100644 index 0000000..a0ee5df --- /dev/null +++ b/scripts/ex/class-final.js @@ -0,0 +1,7 @@ +var Foo = FinalClass( 'Foo', +{ + 'public describe': function() + { + return "I cannot be extended."; + }, +} ); diff --git a/scripts/ex/class.js b/scripts/ex/class.js index a3e6bc9..689fcc3 100644 --- a/scripts/ex/class.js +++ b/scripts/ex/class.js @@ -1,22 +1,16 @@ -// define class Dog -var Dog = Class( 'Dog', -{ - 'private _name': '', +var Class = easejs.Class; - __construct: function( name ) +var Stack = Class( 'Stack', +{ + 'private _stack': [], + + 'public push': function( value ) { - this._name = name; + this._stack.push( value ); }, - 'public bark': function() + 'public pop': function() { - console.log( this._name + ' says: Woof!' ); - } + return this._stack.pop(); + }, } ); - -// invoke method 'bark' on a new instance of 'Dog' -Dog( 'Fluffy' ).bark(); - -// alternatively, we can use the 'new' keyword -var inst = new Dog( 'Bob' ); -inst.bark(); diff --git a/scripts/ex/interface-2.js b/scripts/ex/interface-2.js new file mode 100644 index 0000000..b774c8b --- /dev/null +++ b/scripts/ex/interface-2.js @@ -0,0 +1,25 @@ +var ConcreteFilesystem = Class( 'ConcreteFilesystem' ) + .implement( Filesystem ) // multiple interfaces as separate arguments +{ + 'public open': function( path, mode ) + { + return { path: path, mode: mode }; + }, + + 'public read': function( handle, length ) + { + return ""; + }, + + 'public write': function( handle, data ) + { + // ... + return data.length; + }, + + 'public close': function( handle ) + { + // ... + return this; + }, +} ); diff --git a/scripts/ex/interface-3.js b/scripts/ex/interface-3.js new file mode 100644 index 0000000..724ea22 --- /dev/null +++ b/scripts/ex/interface-3.js @@ -0,0 +1,2 @@ +var inst = ConcreteFilesystem(); +Class.isA( Filesystem, inst ); // true diff --git a/scripts/ex/interface.js b/scripts/ex/interface.js new file mode 100644 index 0000000..33e43ea --- /dev/null +++ b/scripts/ex/interface.js @@ -0,0 +1,10 @@ +var Filesystem = Interface( 'Filesystem', +{ + 'public open': [ 'path', 'mode' ], + + 'public read': [ 'handle', 'length' ], + + 'public write': [ 'handle', 'data' ], + + 'public close': [ 'handle' ], +} ); diff --git a/scripts/ex/static-members.js b/scripts/ex/static-members.js new file mode 100644 index 0000000..8b603c7 --- /dev/null +++ b/scripts/ex/static-members.js @@ -0,0 +1,27 @@ +var Cow = Class( 'Cow', +{ + 'const LEGS': 4, + + 'private static _number': 0, + + __construct: function() + { + // __self refers to the class associated with this instance + this.__self.$( '_number' ) = this.__self.$( 'number' ) + 1; + }, + + 'public static create': function() + { + return Cow(); + }, + + 'public static getNumber': function(){ + { + return this.__self.$( '_number' ); + }, +} ); + +Cow.$( 'LEGS' ); // 4 +Cow.getNumber(); // 0 +Cow.create(); +Cow.getNumber(); // 1 diff --git a/scripts/highlight.pack.js b/scripts/highlight.pack.js new file mode 100644 index 0000000..583a2b3 --- /dev/null +++ b/scripts/highlight.pack.js @@ -0,0 +1 @@ +var hljs=new function(){function m(p){return p.replace(/&/gm,"&").replace(/"}while(y.length||z.length){var v=u().splice(0,1)[0];w+=m(x.substr(r,v.offset-r));r=v.offset;if(v.event=="start"){w+=s(v.node);t.push(v.node)}else{if(v.event=="stop"){var p,q=t.length;do{q--;p=t[q];w+=(""+p.nodeName.toLowerCase()+">")}while(p!=v.node);t.splice(q,1);while(q
"+w.value+"
";u=v.firstChild.firstChild;v.firstChild.cN=r.cN;r.parentNode.replaceChild(v.firstChild,r)}else{u.innerHTML=w.value}u.className=t;u.result={language:s,kw:w.keyword_count,re:w.r};if(w.second_best){u.second_best={language:w.second_best.language,kw:w.second_best.keyword_count,re:w.second_best.r}}}function k(){if(k.called){return}k.called=true;var r=document.getElementsByTagName("pre");for(var p=0;pdiff --git a/includes/header.html b/includes/header.html index 8deb778..2a668e1 100644 --- a/includes/header.html +++ b/includes/header.html @@ -3,8 +3,6 @@
-