1
0
Fork 0

Modernize syntax of examples on index page

We still support ES3 (as long as an ES3 syntax is used, obviously), but
let's not make ourselves look ancient and irrelevant.
website
Mike Gerwitz 2017-10-31 23:09:36 -04:00
parent 3fae8e80e9
commit aac56f4246
Signed by: mikegerwitz
GPG Key ID: 8C917B7F5DC51BA2
13 changed files with 46 additions and 46 deletions

View File

@ -74,8 +74,8 @@
<a href="manual/Temporary-Instances.html" class="man">temporary instances</a>.
</p>
<pre class="js">
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 @@
<tt>extend()</tt> method may be used.
</p>
<pre class="js">
var SturdyCow = Cow.extend( { /*...*/ } );
const SturdyCow = Cow.extend( { /*...*/ } );
</pre>
<p>

View File

@ -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 = '" +

View File

@ -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 = '" +

View File

@ -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 )
{
// ...
},

View File

@ -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!'";
},

View File

@ -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.";
},

View File

@ -1,6 +1,6 @@
var Foo = FinalClass( 'Foo',
const Foo = FinalClass( 'Foo',
{
'public describe': function()
'public describe'()
{
return "I cannot be extended.";
},

View File

@ -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

View File

@ -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();
},

View File

@ -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;

View File

@ -1,2 +1,2 @@
var inst = ConcreteFilesystem();
const inst = ConcreteFilesystem();
Class.isA( Filesystem, inst ); // true

View File

@ -1,4 +1,4 @@
var Filesystem = Interface( 'Filesystem',
const Filesystem = Interface( 'Filesystem',
{
'public open': [ 'path', 'mode' ],

View File

@ -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' );
},