• Code using deprecated __proto__ (see screenshot) works:

    var Obj = function(val) {
    
    
      this.val = (val) ? val : this.__proto__.defaultVal;
    };
    
    Obj.prototype.defaultVal = "defaultVal";
    
    Obj.prototype.getVal = function() {
      return this.val;
    };
    
    var objDefault = new Obj();
    
    console.log("val = " + objDefault.getVal());
    

    Console output:

     1v85 Copyright 2016 G.Williams
    >echo(0);
    val = defaultVal
    =undefined
    > 
    

    Code 'correctly' getting prototype:

    ...
      this.val = (val) ? val : Object.getPrototypeOf(this).defaultVal; // line 4
    ...
    

    Console output:

     1v85 Copyright 2016 G.Williams
    >echo(0);
    Uncaught Error: Function "getPrototypeOf" not found!
     at line 4 col 33
    ...val = (val) ? val : Object.getPrototypeOf(Obj).defaultVal;..­.
                                  ^
    in function "Obj" called from line 1 col 26
    var objDefault = new Obj();
                             ^
    val =
    Uncaught Error: Field or method "getVal" does not already exist, and can't create it on undefined
     at line 1 col 34
    console.log("val = " + objDefault.getVal());
                                     ^
    =undefined
    >
    

    1 Attachment

    • Screen Shot 2016-05-06 at 8.38.46 AM.png
  • This'll be the JSHint (the lint plugin for the Web IDE) picking up on something. __proto__ isn't deprecated in Espruino, although I guess Object.getPrototypeOf should be added at some point.

  • So it's just the linter bitching about __proto__ - Is it actually officially deprecated anywhere or anything, or do they just not like it because it doesn't feel JS-y enough?

    Object.getPrototypeOf is not listed in the reference, so it's no surprise that it's not implemented (the reference list is exhaustive, right? I think it's autogenerated so all methodscd show up, even if there's no info on them).

    Edit: beaten....

  • Thanks. I like the light-weight obj.__proto__ property accessor but understand why it got deprecated and replaced with Object.getPrototypeOf(obj) method.

    I see the challenge of keeping up with JS ECMA... and it will get more intense... ES6... 7. But it is for sure fun and you - including every one else - will not get bored...

  • I'm now thinking IDE could use a (user configurable) profile about what is ultimately fed to the linter... (no pressure on anyone...)

  • I liked __proto__ too, but it does feel a bit hacky :) I'll add an issue for sticking getPrototypeOf in.

    the reference list is exhaustive, right?

    Yep, it's whatever is in the current release of Espruino, so at the moment 1v85. There may be some other stuff in the latest Git build.

    about what is ultimately feed to the linter...

    @allObjects - https://github.com/espruino/EspruinoWebI­DE/blob/gh-pages/js/core/editorJavaScrip­t.js#L29 :)

    I'm not sure it needs to be configurable, but disabling just that warning should be easy.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How come this.__proto__ being deprecated but Object.getPrototypeOf(this) not implemented?

Posted by Avatar for allObjects @allObjects

Actions