How to refer to the current prototype of a class.

Michał Wadas michalwadas at gmail.com
Sun Jul 31 03:12:54 UTC 2016


this.constructor.prototype.baz

On 31 Jul 2016 3:03 a.m., "/#!/JoePea" <joe at trusktr.io> wrote:

> Currently we use
>
> ```js
> class Foo {
>
>   bar() {
>
>     // we want the current prototype's (HomeObject's?) `baz` method, not
> the leafmost prototype's (this') `baz` method.
>     Foo.prototype.baz()
>
>   }
>
>   baz() {
>     // ..
>   }
>
> }
> ```
>
> What about a shorthand keyword like `current` for the "current prototype"?
>
> ```js
> class Foo {
>
>   bar() {
>
>     // we want the current prototype's (HomeObject's?) `baz` method, not
> the leafmost prototype's (this') `baz` method.
>     current.baz()
>
>   }
>
>   baz() {
>     // ..
>   }
>
> }
> ```
>
> What about `prototype`, because that word is, afterall, owned by
> JavaScript (though more likely to break code than `current`).
>
> ```js
> class Foo {
>
>   bar() {
>
>     // we want the current prototype's (HomeObject's?) `baz` method, not
> the leafmost prototype's (this') `baz` method.
>     prototype.baz()
>
>   }
>
>   baz() {
>     // ..
>   }
>
> }
> ```
>
> Or, since `HomeObject` is a thing, maybe a `home` keyword would be
> intuitive, although that is also more likely to break existing code than
> `current`?
>
> ```js
> class Foo {
>
>   bar() {
>
>     // we want the current prototype's (HomeObject's?) `baz` method, not
> the leafmost prototype's (this') `baz` method.
>     home.baz()
>
>   }
>
>   baz() {
>     // ..
>   }
>
> }
> ```
>
> Or a symbol?
>
> ```js
> class Foo {
>
>   bar() {
>
>     // we want the current prototype's (HomeObject's?) `baz` method, not
> the leafmost prototype's (this') `baz` method.
>     #.baz()
>
>   }
>
>   baz() {
>     // ..
>   }
>
> }
> ```
>
> */#!/*JoePea
>
> _______________________________________________
> 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/20160731/e5c41f25/attachment.html>


More information about the es-discuss mailing list