From aac56f42462aefcf6dfec6aab1c9c872e330e493 Mon Sep 17 00:00:00 2001
From: Mike Gerwitz
- var inst = Foo( "John Doe" ); - var inst = new Foo( "John Doe" ); + const inst_a = Foo( "John Doe" ); + const inst_b = new Foo( "John Doe" ); // temporary instance Foo( "John Doe" ).sayHello(); @@ -103,7 +103,7 @@ extend() method may be used.- var SturdyCow = Cow.extend( { /*...*/ } ); + const SturdyCow = Cow.extend( { /*...*/ } );diff --git a/scripts/ex/access-modifiers-implicit.js b/scripts/ex/access-modifiers-implicit.js index 7801178..e83a3c2 100644 --- a/scripts/ex/access-modifiers-implicit.js +++ b/scripts/ex/access-modifiers-implicit.js @@ -1,34 +1,34 @@ -var DatabaseRecord = Class( 'DatabaseRecord', +const DatabaseRecord = Class( 'DatabaseRecord', { /* implicitly private */ _connection: null, - __construct: function( host, user, pass ) + constructor( host, user, pass ) { this._connection = this._connect( host, user, pass ); }, /* implicitly private */ - _connect: function( host, user, pass ) + _connect( host, user, pass ) { // (do connection stuff) return { host: host }; }, - 'protected query': function( query ) + 'protected query'( query ) { // perform query on this._connection, rather than exposing // this._connection to subtypes }, - 'protected escapeString': function( field ) + 'protected escapeString'( field ) { return field.replace( "'", "\\'" ); }, /* public by default */ - getName: function( id ) + getName( id ) { return this._query( "SELECT name FROM users WHERE id = '" + diff --git a/scripts/ex/access-modifiers.js b/scripts/ex/access-modifiers.js index 54bf9a9..bc37916 100644 --- a/scripts/ex/access-modifiers.js +++ b/scripts/ex/access-modifiers.js @@ -1,31 +1,31 @@ -var DatabaseRecord = Class( 'DatabaseRecord', +const DatabaseRecord = Class( 'DatabaseRecord', { 'private _connection': null, - __construct: function( host, user, pass ) + constructor( host, user, pass ) { this._connection = this._connect( host, user, pass ); }, - 'private _connect': function( host, user, pass ) + 'private _connect'( host, user, pass ) { // (do connection stuff) return { host: host }; }, - 'protected query': function( query ) + 'protected query'( query ) { // perform query on this._connection, rather than exposing // this._connection to subtypes }, - 'protected escapeString': function( field ) + 'protected escapeString'( field ) { return field.replace( "'", "\\'" ); }, - 'public getName': function( id ) + 'public getName'( id ) { return this._query( "SELECT name FROM users WHERE id = '" + diff --git a/scripts/ex/class-abstract.js b/scripts/ex/class-abstract.js index 3441c8b..b2aa514 100644 --- a/scripts/ex/class-abstract.js +++ b/scripts/ex/class-abstract.js @@ -1,6 +1,6 @@ -var Database = AbstractClass( 'Database', +const Database = AbstractClass( 'Database', { - 'public connect': function( user, pass ) + 'public connect'( user, pass ) { if ( !( this.authenticate( user, pass ) ) ) { @@ -12,11 +12,11 @@ var Database = AbstractClass( 'Database', 'abstract protected authenticate': [ 'user', 'pass' ], } ); -var MongoDatabase = Class( 'MongoDatabase' ) +const MongoDatabase = Class( 'MongoDatabase' ) .extend( Database, { // must implement each argument for Database.authenticate() - 'protected authenticate': function( user, pass ) + 'protected authenticate'( user, pass ) { // ... }, diff --git a/scripts/ex/class-anon.js b/scripts/ex/class-anon.js index d16947b..f37b9ed 100644 --- a/scripts/ex/class-anon.js +++ b/scripts/ex/class-anon.js @@ -1,12 +1,12 @@ -var Foo = Class( +const Foo = Class( 'private _name': '', - __construct: function( name ) + constructor( name ) { this._name = ''+( name ); }, - 'public sayHello': function() + 'public sayHello'() { return this._name + " says 'Hello!'"; }, diff --git a/scripts/ex/class-extend.js b/scripts/ex/class-extend.js index 9914781..3527c0d 100644 --- a/scripts/ex/class-extend.js +++ b/scripts/ex/class-extend.js @@ -1,15 +1,15 @@ -var Cow = Class( 'Cow', +const Cow = Class( 'Cow', { - 'virtual public tip': function() + 'virtual public tip'() { return "Omph."; }, } ); -var SturdyCow = Class( 'SturdyCow' ) +const SturdyCow = Class( 'SturdyCow' ) .extend( Cow, { - 'override public tip': function() + 'override public tip'() { return "Moo."; }, diff --git a/scripts/ex/class-final.js b/scripts/ex/class-final.js index a0ee5df..e91c377 100644 --- a/scripts/ex/class-final.js +++ b/scripts/ex/class-final.js @@ -1,6 +1,6 @@ -var Foo = FinalClass( 'Foo', +const Foo = FinalClass( 'Foo', { - 'public describe': function() + 'public describe'() { return "I cannot be extended."; }, diff --git a/scripts/ex/class-poly.js b/scripts/ex/class-poly.js index c5b32cb..44d4b03 100644 --- a/scripts/ex/class-poly.js +++ b/scripts/ex/class-poly.js @@ -1,5 +1,5 @@ -var cow = Cow(), - sturdy = SturdyCow(); +const cow = Cow(); +const sturdy = SturdyCow(); Class.isA( Cow, cow ); // true Class.isA( SturdyCow, cow ); // false diff --git a/scripts/ex/class.js b/scripts/ex/class.js index 689fcc3..c0e0f6b 100644 --- a/scripts/ex/class.js +++ b/scripts/ex/class.js @@ -1,15 +1,15 @@ -var Class = easejs.Class; +const { Class } = easejs; -var Stack = Class( 'Stack', +const Stack = Class( 'Stack', { 'private _stack': [], - 'public push': function( value ) + 'public push'( value ) { this._stack.push( value ); }, - 'public pop': function() + 'public pop'() { return this._stack.pop(); }, diff --git a/scripts/ex/interface-2.js b/scripts/ex/interface-2.js index b774c8b..773f3d7 100644 --- a/scripts/ex/interface-2.js +++ b/scripts/ex/interface-2.js @@ -1,23 +1,23 @@ -var ConcreteFilesystem = Class( 'ConcreteFilesystem' ) +const ConcreteFilesystem = Class( 'ConcreteFilesystem' ) .implement( Filesystem ) // multiple interfaces as separate arguments { - 'public open': function( path, mode ) + 'public open'( path, mode ) { return { path: path, mode: mode }; }, - 'public read': function( handle, length ) + 'public read'( handle, length ) { return ""; }, - 'public write': function( handle, data ) + 'public write'( handle, data ) { // ... return data.length; }, - 'public close': function( handle ) + 'public close'( handle ) { // ... return this; diff --git a/scripts/ex/interface-3.js b/scripts/ex/interface-3.js index 724ea22..f8f38ab 100644 --- a/scripts/ex/interface-3.js +++ b/scripts/ex/interface-3.js @@ -1,2 +1,2 @@ -var inst = ConcreteFilesystem(); +const inst = ConcreteFilesystem(); Class.isA( Filesystem, inst ); // true diff --git a/scripts/ex/interface.js b/scripts/ex/interface.js index 33e43ea..5c4822e 100644 --- a/scripts/ex/interface.js +++ b/scripts/ex/interface.js @@ -1,4 +1,4 @@ -var Filesystem = Interface( 'Filesystem', +const Filesystem = Interface( 'Filesystem', { 'public open': [ 'path', 'mode' ], diff --git a/scripts/ex/static-members.js b/scripts/ex/static-members.js index 8b603c7..b9bc3e4 100644 --- a/scripts/ex/static-members.js +++ b/scripts/ex/static-members.js @@ -1,21 +1,21 @@ -var Cow = Class( 'Cow', +const Cow = Class( 'Cow', { 'const LEGS': 4, 'private static _number': 0, - __construct: function() + constructor() { // __self refers to the class associated with this instance - this.__self.$( '_number' ) = this.__self.$( 'number' ) + 1; + this.__self.$( '_number' ) = this.__self.$( '_number' ) + 1; }, - 'public static create': function() + 'public static create'() { return Cow(); }, - 'public static getNumber': function(){ + 'public static getNumber'() { return this.__self.$( '_number' ); },