-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new section on scoping JS code #13041
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation looks clear and good to me. Maybe we can link to some external document if the reader wants more information on this subject.
I left some minor grammar nitpicks, I'm not totally sure if all my suggestions are correct as English is not my main language.
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
Thanks for copy-writing @jorgefilipecosta ! ❤️ Your comments were addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, I think this is excellent and an invaluable resource. (I even learned a thing or two!)
I tried to suggest some edits that simplify the overall tone a bit, and try to be a bit kinder to less-skilled developers. My hope is that these edits don't take away from the technical nature of the doc while still making it a little easier to understand if you're not too tech-savvy.
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
@jorgefilipecosta @chrisvanpatten I wasn't too fond of the original example, so I've rewritten it a bit. I've also merged Chris suggestions, which make the text a lot easier to follow (thanks!). Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two tiny tweaks but I'll approve so we can merge quickly. Really nicely done on this, and the improvements with the example are great too — they make it a lot clearer!
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
docs/designers-developers/developers/tutorials/javascript/scope-your-code.md
Outdated
Show resolved
Hide resolved
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
…e-your-code.md Co-Authored-By: nosolosw <nosolosw@users.noreply.github.com>
The page is published in the handbook and the navigation menu, but the contents are void. Reverting while figuring out what happened.
|
||
Notice the _historically_. | ||
|
||
JavaScript has evolved quite a bit since its creation. As of 2015, the language supports modules, also known as _ES6 modules_, that introduce separate scope per file: a global variable in `first.js` wouldn't be exposed to `second.js`. This feature is already [supported by modern browsers](https://caniuse.com/#feat=es6-module), but not all of them do. If your code needs to run in browsers that don't support modules, your last resort is using IIFEs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to surface that it's not needed for ES6 very early in the file for more clarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intent was making this as free as jargon as possible as to make it more palatable to people not exposed to modern JavaScript just yet, that's why I only hinted at ES6 by the end of the file.
One way I think this tutorial could be expanded is by adding a section that includes a minimum viable mechanism to compile from ES6 to ES5 (including JSX). I was tempted to adapt my own dumb webpack explanation for the handbook. Upon sleeping on it, I think that a better use of everyone's time (the writer and the reader) will be to walk the reader through a minimal setup instead - that way we give developers an easy and practical way to get started and avoid the analysis paralysis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate tutorial for build setup would be good, but we should probably wait for @wordpress/scripts improvements first and use it instead of using the tools directly cc @gziolo. I was more thinking of a random person arriving into this tutorial. They might already use ES6. So just a small note at the beginning could be useful IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think we will need to add a tutorial about using wp-scripts
in your project. There are three things that need happen before we can start promoting it:
- Scripts: Add support for start and build scripts to the package
- Re-use webpack and babel config for build script
- All packages need to be published to npm
@nosolosw would you like to work together on such tutorial?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to! Ping me in any PR that lacks a reviewer and I'll be there. When pieces are in place, I can also pair to write the tutorial.
This PR has been created as a response to this comment by Marcus.