Minimalist Classes
Brendan Eich
brendan at mozilla.com
Wed Nov 2 19:00:01 PDT 2011
Updated: https://gist.github.com/1332193
$ git commit -a -m"Updates per conversations with @dflanagan and @allenwb."
git diff output below. Exec. summary: prefix groups via { ... } and public @-namespace population to avoid "this." sad-making verbosity.
/be
diff --git a/minimalist-classes.js b/minimalist-classes.js
index 18a7a8c..6f25144 100644
--- a/minimalist-classes.js
+++ b/minimalist-classes.js
@@ -188,8 +188,11 @@ class Monster {
// See the new sameName method for an example of infix and prefix @ in action.
//
// David Flanagan suggests keeping the unary-prefix @foo shorthand, but making
-// the long-hand obj. at foo. Breaks E4X but no matter -- I'm open to it, but it
-// is not essential to bikeshed here.
+// the long-hand obj. at foo. Breaks E4X but no matter -- but the win is that the
+// [no LineTerminator here] restriction on the left of unary-prefix @ is not
+// needed. Also the references don't grep like email addresses, which counts
+// with David and me. So I've incorporated David's suggestion. See other. at name
+// etc. below.
//
// There is no const instance variable declaration. Non-writable instance vars
// (properties to most people) are quite rare. Use ES5's Object.defineProperty
@@ -203,15 +206,17 @@ class Monster {
class Monster {
- private name, health;
+ private { name, health }, // can group a prefix, same for const and static
+ public flair, // you should have 37 pieces of public flair
constructor(name, health) {
@name = name;
@health = health;
+ @flair = 0;
}
sameName(other) {
- return @name === other at name;
+ return @name === other. at name;
}
private attackHelper(target) {
On Nov 1, 2011, at 6:56 PM, Brendan Eich wrote:
> On Nov 1, 2011, at 5:18 PM, Brendan Eich wrote:
>
>> On Oct 31, 2011, at 6:57 PM, Jeremy Ashkenas wrote:
>>
>>> 'Evening, ES-Discuss.
>>>
>>> After poking a stick in the bees' nest this morning (apologies, Allen), and in the spirit of loyal opposition, it's only fair that I throw my hat in the ring.
>>>
>>> Here is a proposal for minimalist JavaScript classes that enable behavior that JavaScripters today desire (as evidenced by libraries and languages galore), without adding any new semantics beyond what already exists in ES3.
>>>
>>> https://gist.github.com/1329619
>>>
>>> Let me know what you think, and feel free to fork.
>>
>> Thanks, I did fork, and I made a Rich Corinthian Leather version, for the reasons given in the comments. In brief, I contend that over-minimizing will please no one: class haters still gonna hate, while class lovers used to batteries-and-leather-included will find the bare sheet metal poky and painful.
>>
>> Love it or hate it, I'm ok either way :-P. But I do crave intelligent responses.
>
> Handy link included: https://gist.github.com/1332193
>
> /be
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111102/a4e7a8ec/attachment.html>
More information about the es-discuss
mailing list