René's URL Explorer Experiment


Title: Field declarations overwrite properties on the prototype · Issue #151 · tc39/proposal-class-fields · GitHub

Open Graph Title: Field declarations overwrite properties on the prototype · Issue #151 · tc39/proposal-class-fields

X Title: Field declarations overwrite properties on the prototype · Issue #151 · tc39/proposal-class-fields

Description: I think this issue has been raised a few times already in several of the open issues, like #100, but I thought it would probably be good to report a very specific, real life use case. The following snippet is the official way to enhance ...

Open Graph Description: I think this issue has been raised a few times already in several of the open issues, like #100, but I thought it would probably be good to report a very specific, real life use case. The following...

X Description: I think this issue has been raised a few times already in several of the open issues, like #100, but I thought it would probably be good to report a very specific, real life use case. The following...

Opengraph URL: https://github.com/tc39/proposal-class-fields/issues/151

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Field declarations overwrite properties on the prototype","articleBody":"I think this issue has been raised a few times already in several of the open issues, like #100, but I thought it would probably be good to report a very specific, real life use case. \r\n\r\nThe following snippet is the official way to enhance a class with observable capabalities in [MobX](https://github.com/mobxjs/mobx), when decorator syntax is not used. (See [`decorate` docs](https://mobx.js.org/refguide/api.html#-decorate))\r\n\r\n```javascript\r\nclass Counter {\r\n  counter = 0\r\n}\r\n\r\ndecorate(Counter, { counter: observable })\r\n```\r\n\r\nWhich is currently semantically equivalent to:\r\n\r\n```javascript\r\nclass Counter {\r\n  @observable counter = 0\r\n}\r\n```\r\n\r\nThis first example works fine with TypeScript and [babel-plugin-proposal-class-properties](https://babeljs.io/docs/en/next/babel-plugin-proposal-class-properties.html), but only if `loose` mode is used (that translates the initializes to an assignment in the constructor). In standards mode, this mechanism no longer works. \r\n\r\nThe simple reason is, the `decorate` call introduces the `count` property on the `Counter` property, and gives it a getter and setter. If just an assignment is made in the constructor, this works fine. However, if a new property is introduces, the property on the prototype is completely ignored and a new one is introduced on the instance. \r\n\r\nIn pseudo code `decorate` does something along these lines: \r\n\r\n```javascript\r\nclass Counter {\r\n    counter = 3\r\n}\r\n\r\nObject.defineProperty(Counter.prototype, \"counter\", {\r\n  set(counter) {\r\n    this._counter = counter * 2 \r\n  },\r\n  get() {\r\n    return this._counter * 2 \r\n  }\r\n})\r\n\r\nconst counter = new Counter()\r\n\r\nconsole.log(counter.counter)\r\n```\r\n\r\nPrinting the `counter` will yield `12` in loose mode, but `3` in standards mode, as in standards mode the field would be re-introduced in a non-interceptable way.\r\n\r\n---\r\n\r\nI search this repo for it, but couldn't really find it, what was the motivation to change the spec in this regards? (or if it never changed; what is the motivation to deviate from what existing transpilers are doing?).\r\n\r\nAnd more specific: how could I express \"decorating\" my class fields in the future with the above API? After all, changing a prototype after the initial class declaration is not that uncommon in JavaScript. \r\n\r\n---\r\n\r\nA potentially future risk of this approach is that it will render MobX completely incompatible with create-react-app, if this proposal is finalized before the decorators standard, as the `decorate` utility is currently the only way in which CRA users can obtain decorator-like behavior without the syntax. For some background: https://mobx.js.org/best/decorators.html\r\n\r\nN.B. note that this problem also happens when the field is declared, but never initialized.\r\n\r\n---\r\n\r\n_Edit: for clarification to other readers of this issue, the difference in compilation between loose and standards mode is:_\r\n\r\n```javascript\r\n// Loose:\r\nvar Counter = function Counter() {\r\n   this.x = 3 // assignment being picked up by property on the prototype\r\n}\r\n\r\n// Standard:\r\nvar Counter = function Counter() {\r\n   Object.defineProperty(obj, \"counter\", { // Property definition hides prototype property\r\n      value: 3,\r\n      enumerable: true,\r\n      configurable: true,\r\n      writable: true\r\n    });\r\n};\r\n```\r\n","author":{"url":"https://github.com/mweststrate","@type":"Person","name":"mweststrate"},"datePublished":"2018-10-17T19:31:16Z","url":"https://github.com/tc39/proposal-class-fields/issues/151"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2f8cff5f-1161-479f-ec81-652b3badd383
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA60E:117B4D:2E6752:3F8A94:6AED7974
html-safe-nonce2a3cb70b2e95e08960c83b039a158558e224d8bc38a93c24605ae26871d354bc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjBFOjExN0I0RDoyRTY3NTI6M0Y4QTk0OjZBRUQ3OTc0IiwidmlzaXRvcl9pZCI6IjY5OTcxNjExNDk0NTI0MzUwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac7aab8d2c5443bc3b68cf1eb2c4d07ecb5195ab6be2c6694b68582c1f72e559b0
hovercard-subject-tagissue:371233558
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/tc39/proposal-class-fields/151/issue_layout
twitter:imagehttps://opengraph.githubassets.com/193c214c133cd142ed647ecb48601d51458ef41867bce9effe84b1d9ed28e553/tc39/proposal-class-fields/issues/151
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/193c214c133cd142ed647ecb48601d51458ef41867bce9effe84b1d9ed28e553/tc39/proposal-class-fields/issues/151
og:image:altI think this issue has been raised a few times already in several of the open issues, like #100, but I thought it would probably be good to report a very specific, real life use case. The following...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemweststrate
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/tc39/proposal-class-fields git https://github.com/tc39/proposal-class-fields.git
octolytics-dimension-user_id1725583
octolytics-dimension-user_logintc39
octolytics-dimension-repository_id91250837
octolytics-dimension-repository_nwotc39/proposal-class-fields
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id91250837
octolytics-dimension-repository_network_root_nwotc39/proposal-class-fields
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/tc39/proposal-class-fields/issues/151#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftc39%2Fproposal-class-fields%2Fissues%2F151
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ftc39%2Fproposal-class-fields%2Fissues%2F151
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=tc39%2Fproposal-class-fields
Reloadhttps://github.com/tc39/proposal-class-fields/issues/151
Reloadhttps://github.com/tc39/proposal-class-fields/issues/151
Reloadhttps://github.com/tc39/proposal-class-fields/issues/151
tc39https://github.com/tc39
proposal-class-fieldshttps://github.com/tc39/proposal-class-fields
Codehttps://github.com/tc39/proposal-class-fields
Issues36 (36)https://github.com/tc39/proposal-class-fields/issues
Pull requests1 (1)https://github.com/tc39/proposal-class-fields/pulls
Actionshttps://github.com/tc39/proposal-class-fields/actions
Security and qualityhttps://github.com/tc39/proposal-class-fields/security
Insightshttps://github.com/tc39/proposal-class-fields/pulse
https://github.com/tc39/proposal-class-fields
Field declarations overwrite properties on the prototypehttps://github.com/tc39/proposal-class-fields/issues/151#top
https://github.com/mweststrate
mweststratehttps://github.com/mweststrate
on Oct 17, 2018https://github.com/tc39/proposal-class-fields/issues/151#issue-371233558
#100https://github.com/tc39/proposal-class-fields/issues/100
MobXhttps://github.com/mobxjs/mobx
decorate docshttps://mobx.js.org/refguide/api.html#-decorate
babel-plugin-proposal-class-propertieshttps://babeljs.io/docs/en/next/babel-plugin-proposal-class-properties.html
https://mobx.js.org/best/decorators.htmlhttps://mobx.js.org/best/decorators.html
Nexthttps://github.com/tc39/proposal-class-fields/issues/151?timeline_page=1
https://github.com/bakkot
bakkothttps://github.com/bakkot
on Oct 17, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-430765230
herehttps://github.com/tc39/proposal-class-fields/issues/144#issuecomment-430330773
herehttps://github.com/rwaldron/tc39-notes/blob/096b8af38c4b4b9684b09692a70938d49b5451a7/es7/2017-01/jan-26.md
https://github.com/littledan
littledanhttps://github.com/littledan
on Oct 17, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-430765410
as we discussedhttps://github.com/tc39/proposal-decorators/issues/44
this summaryhttps://github.com/tc39/proposal-class-public-fields/issues/42
@bakkothttps://github.com/bakkot
https://github.com/mweststrate
mweststratehttps://github.com/mweststrate
on Oct 17, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-430790026
#42https://github.com/tc39/proposal-class-fields/pull/42
#42https://github.com/tc39/proposal-class-fields/pull/42
https://github.com/rdking
rdkinghttps://github.com/rdking
on Oct 17, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-430790316
@bakkothttps://github.com/bakkot
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431006824
@bakkothttps://github.com/bakkot
@haxhttps://github.com/hax
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431009305
https://github.com/mweststrate
mweststratehttps://github.com/mweststrate
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431010871
@mbrownehttps://github.com/mbrowne
https://twitter.com/SeaRyanC/status/1052621631594553344https://twitter.com/SeaRyanC/status/1052621631594553344
https://github.com/rdking
rdkinghttps://github.com/rdking
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431100737
@mbrownehttps://github.com/mbrowne
@bakkothttps://github.com/bakkot
https://github.com/ljharb
ljharbhttps://github.com/ljharb
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431109748
https://github.com/rdking
rdkinghttps://github.com/rdking
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431119061
@ljharbhttps://github.com/ljharb
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431127585
@rdkinghttps://github.com/rdking
#150 (comment)https://github.com/tc39/proposal-class-fields/issues/150#issuecomment-431121659
@RyanCavanaughhttps://github.com/RyanCavanaugh
https://github.com/rdking
rdkinghttps://github.com/rdking
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431129009
@mbrownehttps://github.com/mbrowne
https://github.com/yyx990803
yyx990803https://github.com/yyx990803
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431130535
https://github.com/nicolo-ribaudo
nicolo-ribaudohttps://github.com/nicolo-ribaudo
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431139735
https://github.com/hax
haxhttps://github.com/hax
on Oct 18, 2018https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-431147631
https://github.com/ljharb
ljharbhttps://github.com/ljharb
on Jul 8, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-509410914
@jhpratthttps://github.com/jhpratt
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Jul 8, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-509413516
https://github.com/tc39/proposal-class-fields/blob/master/README.md#public-fields-created-with-objectdefinepropertyhttps://github.com/tc39/proposal-class-fields/blob/master/README.md#public-fields-created-with-objectdefineproperty
https://github.com/rdking
rdkinghttps://github.com/rdking
on Jul 8, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-509414402
https://github.com/justinbmeyer
justinbmeyerhttps://github.com/justinbmeyer
on Jul 26, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-515582512
https://github.com/rdking
rdkinghttps://github.com/rdking
on Jul 26, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-515589485
@justinbmeyerhttps://github.com/justinbmeyer
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Jul 26, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-515629000
@justinbmeyerhttps://github.com/justinbmeyer
babel plugin for decoratorshttps://babeljs.io/docs/en/babel-plugin-proposal-decorators
https://github.com/tc39/proposal-decorators#sethttps://github.com/tc39/proposal-decorators#set
https://github.com/justinbmeyer
justinbmeyerhttps://github.com/justinbmeyer
on Jul 27, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-515640042
@mbrownehttps://github.com/mbrowne
https://github.com/rdking
rdkinghttps://github.com/rdking
on Jul 27, 2019https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-515643028
@justinbmeyerhttps://github.com/justinbmeyer
https://github.com/anatoliyarkhipov
anatoliyarkhipovhttps://github.com/anatoliyarkhipov
on Jan 10, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-757441991
https://user-images.githubusercontent.com/1934180/104118677-5cc84b80-5333-11eb-9d90-8db2583d16b4.png
https://github.com/Venryx
Venryxhttps://github.com/Venryx
on Sep 5, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-913153736
https://jsbench.me/o6kt78il9e/1https://jsbench.me/o6kt78il9e/1
https://camo.githubusercontent.com/5da02d4f6e7e453148b0a51eae0ed05557a7b4e143a7440396c9bebf358209d3/68747470733a2f2f692e696d6775722e636f6d2f445063375752342e706e67
useDefineForClassFieldhttps://www.typescriptlang.org/tsconfig#useDefineForClassFields
https://github.com/michaelficarra
michaelficarrahttps://github.com/michaelficarra
on Sep 5, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-913172340
@Venryxhttps://github.com/Venryx
https://github.com/mbrowne
mbrownehttps://github.com/mbrowne
on Sep 5, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-913175083
@Venryxhttps://github.com/Venryx
https://github.com/Venryx
Venryxhttps://github.com/Venryx
on Sep 7, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-914184014
@Venryxhttps://github.com/Venryx
https://jsbench.me/o6kt78il9e/2https://jsbench.me/o6kt78il9e/2
https://camo.githubusercontent.com/2f9fd4e5bd3609d07277d24a62f9363eb832f76f0d1b71ffca375a534013c36b/68747470733a2f2f692e696d6775722e636f6d2f456d79347036652e706e67
https://github.com/nicolo-ribaudo
nicolo-ribaudohttps://github.com/nicolo-ribaudo
on Sep 7, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-914264342
@Venryxhttps://github.com/Venryx
https://github.com/dgreensp
dgreensphttps://github.com/dgreensp
on Oct 12, 2021https://github.com/tc39/proposal-class-fields/issues/151#issuecomment-940645130
https://caniuse.com/mdn-javascript_classes_public_class_fieldshttps://caniuse.com/mdn-javascript_classes_public_class_fields
Sign up for freehttps://github.com/signup?return_to=https://github.com/tc39/proposal-class-fields/issues/151
Sign in to commenthttps://github.com/login?return_to=https://github.com/tc39/proposal-class-fields/issues/151
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.