1
0
Fork 0
easejs/test/ClassBuilder
Mike Gerwitz ba2605f836 Alias `constructor` member to `__construct`
This allows ease.js classes to mimic the structure of ES6 classes, which use
`constructor` to denote the constructor.  This patch simply aliases it to
`__construct`, which ease.js handles as it would normally.

To that note, since the ES6 `class` keyword is purely syntatic sugar around
the prototype model, there is not much benefit to using it over ease.js if
benefits of ease.js are still desired, since the member definition syntax is
a feature of object literals:

```
// ease.js using ES6
let Person = Class(
{
    _name: '',

    // note that __construct still works as well
    constructor( name ) {
      this._name = ''+name;
    },

    sayHi() {
      return "Hi, I'm " + this.getName();
    },

    // keywords still work as expected
    'protected getName'() {
      return this._name;
    }
} );

// ES6 using `class` keyword
class Person
{
    // note that ES6 will _not_ make this private
    _name: '',

    constructor( name ) {
      this._name = ''+name;
    },

    sayHi() {
      return "Hi, I'm " + this.getName();
    }

    // keywords unsupported (you'd have to use Symbols)
    getName() {
      return this._name;
    }
}

// ES3/5 ease.js
var Person = Class(
{
    _name: '',

    __construct: function( name ) {
      this._name = ''+name;
    },

    sayHi: function() {
      return "Hi, I'm " + this._name;
    },

    'protected getName': function() {
      return this._name;
    }
} );
```

As you can see, the only change between writing ES6-style method definitions
is the syntax; all keywords and other features continue to work as expected.
2015-09-16 00:02:00 -04:00
..
ConstTest.js Extracted warning handlers into their own prototypes 2014-06-11 23:42:20 -04:00
FinalTest.js Extracted warning handlers into their own prototypes 2014-06-11 23:42:20 -04:00
InstanceTest.js [copyright] Copyright update 2015-05-28 01:01:51 -04:00
MemberRestrictionTest.js Alias `constructor` member to `__construct` 2015-09-16 00:02:00 -04:00
StaticTest.js Extracted warning handlers into their own prototypes 2014-06-11 23:42:20 -04:00
VisibilityTest.js Extracted warning handlers into their own prototypes 2014-06-11 23:42:20 -04:00