Sealing is a good thing, and I operate everything under strict mode, anyway. kdex, I just read the strong mode proposal, and it's great. It's literally my list of things I've run into, I'll be happy to see that -- or at least parts of it -- make it into the spec and major browsers. I have no say but I still silently vote yes!

Anything that makes it easier to statically analyze instead of having to dynamically analyze it and also disallow some of the things that creates hard to track errors would be great.

My current code is enormous and it would be nice -- as it's not compiled but tested by running -- your regular development environments could better detect errors during syntax highlighting -- being able to more statically analyze the code would be a boon for our coding cycles.

[>] Brian

On 3/18/2016 11:16 AM, kdex wrote:
Note that this does prevent extensions, but will only throw in strict
mode. In sloppy mode, the assignment will silently fail.

On 18.03.2016 15:07, Michael Theriot wrote:
You can accomplish this by calling `Object.seal(this)` in the constructor.

```js
constructor() {
  this.x = 1;
  Object.seal(this);
}
```

On Fri, Mar 18, 2016 at 8:36 AM, Brian Barnes <[email protected]
<mailto:[email protected]>> wrote:

    I know properties on classes are getting a look over for the next
    iteration (last I checked) and I understand javascript is
    obviously a different language then other oo languages with a
    different foundation, but I bring this up for it's usage in
    producing stricter code that reduces errors and is easier to
    analyze.  A vote for this if anybody considered it!

    class Test
    {

    constructor()
    {
      this.x=1;
    }

    func1()
    {
      this.y=2;
    }

    func2()
    {
      console.log(this.x+','+this.y);
    }
    }

    var test1=new Test();
    test1.func1();
    test2.func2(); // outputs 1,2

    var test2=new Test();
    test2.func(); // outputs 1,undefined

    I know classes contents are meant to be in strict mode, and I
    thinking that only allowing properties to be created in the
    constructor (or eventually static properties on the class itself)
    would make a system less prone to the conditions like you see
    above.  Basically, func1() would produce a error when run.

    I can see why this type of initialization of properties could be
    desired, though, especially as it reflect the way it would have
    worked if you used a function instead of a class.

    [>] Brian
    _______________________________________________
    es-discuss mailing list
    [email protected] <mailto:[email protected]>
    https://mail.mozilla.org/listinfo/es-discuss




_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to