Modern JavaScript Tutorial
javascript.info
javascript.info
I've used them before for doing stupid reflection hacks (literally just used them today to build a debug UI where I can make sliders out of objects), but it's not code I would really want to ship in production.
bind creates a new function that is bound to a specified receiver.
class Thing {
method1 = () => {}
method2 = () => {
something.addEventListener('click', this.method1);
}
}... but yes - a 'Modern' approach means calling out risks, or more abruptly - that which may even be considered 'anti pattern' inherent in a language as it evolves over time, with hindsight.
Perhaps the most preeminent example would be pointers in C++ - which we generally know to use with 'smart pointers'.
If C++ 'were designed today' - among other things, it'd be likely that 'smart pointers' would be 'default' and they'd be more deeply and seamlessly integrated, and 'direct memory reference' would be seen as a 'thing to do only if necessary' and a bit of a 'corner case'. Necessary, and common enough, surely as in that level of programming we are going to 'go there', however, it's something we wouldn't see as normal practice, rather something we do but with some other idioms, APIs and conventions around it ... possibly with demarcations of 'unsafe' a bit like Rust.
I think it's important, because these are precisely the things that young developers may become entangled in. It should be more like: "By the way this is how this works, but you may want to think twice about using it, here are some cases where it might be 'ok', here are some cases where it's not".
But I don't want to take away from good authorship either, we depend a lot on people stepping up to the plate and doing this work. As an aside, it seems almost perverse that 'Big Corps' just don't do this themselves. I mean, if AWS uses JS extensively, it'd seem reasonable (even from a selfish perspective) for them to 'just do' a comprehensive, JS set of docs.
It's weird that the world depends on 'a few nice dudes/dudettes' to maintain something like 'caniuse.com' and the plethora of other such important works.
Smart pointers are nice and all that but I have yet figured out how to mix them with code which doesn’t use them which is like 99.9% of all library code.
Not to mention that interfacing with C code (like python extensions) are basically impossible unless the calling code is responsible for the object lifetimes. I don’t know how language de jour deals with this C interop but have read it is a pain point almost universally.
Even some of the newer languages I see posted here have manual memory management as the default.
That's what the "more deeply and seamlessly integrated" would be mostly about.
I tends to avoid smart pointers. There are too many variants, supported in different c++ version. Can't reasonably track which one is supported in which compiler
They are a messy bandaid.
The notion of using them in lieu of 'nothing' is rational - but the application is a mess.
We need a clean version of C++ that's not some gigantic new thing.
Smart pointers are unified since C++11 standard with support in all modern compilers for various platform. Invest some time to get familiar with them and you will not regret.
Now, not using 1% of a language seems common. There are plenty of parts of C, C++, C#, Java, Python, etc that I rarely run into.
On the other hand, for testing, mocking, polyfilling, etc call/bind/apply are invaluable.
For writing libraries to do those things call/bind/apply are useful, but most developers aren't doing that very often.
As a oldschool Amiga/PCDOS/ASM/C developer who moved on to the web ten years later... it always feels awkward to me to do things like arr = [...arr, ...arr2] because I'm always wondering just how effectively that is handled by the Javascript compiler.
But as a fellow former low-level, my humble advice is: stop worrying and write clear code. Clear code eventually will run fast and stay clear. Nuanced code eventually will run as fast but stay nuanced.
To be fair, C++ is the epitome of a language you only adopt after consciously picking a very specific subset of features, or explicitly marking features as verboten. Template metaprogramming and exceptions are perhaps two of the most popular features that are routinely banished from C++ projects.
fn = (a -> b) -> a
So your typical array mapping becomes list.map(to(v => v * 2))
All very contrived of course.Ramda’s currying [0] gives you the _ param to play with the order. But I’ve come to the conclusion that currying in JS is rarely worth the effort. [1]
0 - https://github.com/ramda/ramda/blob/v0.28.0/source/__.js
That said, I did use it a TON in the jQuery days (event handlers).
Also, the new React beta docs at https://beta.reactjs.org teach function components rather than classes, and thus there's no use of `.bind()` at all.
Personally, I like to extract larger arrow functions and I am a fan of traditional function declarations in some situations over `const x = () => {}` style function assignment (I feel the latter unnecessarily clutters up code above the logic of the specific component, service or module since it must be declared prior to being used.) Those preferences do lead to needing an understanding of bind, call and apply. Or maybe understanding bind, call and apply lead to me feeling comfortable using those patterns?
Edit to add a bit of history: I started doing this when writing a fair amount of jQuery with a lot of event handlers. And while anonymous or arrow functions worked, the code was soo much cleaner when you put the handler functions below the regular logic. If someone wants to see what a handler function does, it's easy to go down and look, but otherwise, a good name is all that is important. These days, I follow similar patterns, extracting code that doesn't need to be inline into a function that can be referenced as needed, but doesn't need to be inline in the code all of the time.
I don't think is a specific thing of JS. The same happen with almost any language, product features...
With frameworks, it's easy to avoid them and unless you write lots of vanilla or you roll your own framework, they just don't come up, and therefore I expect my colleagues (and me) to just mess things up when we try to use them.
I saw .call just a few hours ago because until recently it was the safe way to call hasOwnProperty[1].
1: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty#using_hasownproperty_as_a_property_namehttps://blog.isquaredsoftware.com/series/how-web-apps-work
The "Interneting Is Hard" HTML+CSS page is one of the best intro resources I've found for those topics, as is the "Modern JS Tutorial", and I specifically linked those as recommended resources from the related posts I wrote.
I did a presentation last year that provided some general guidelines and suggested approaches to debugging, as well as specific info on the standard controls used in GUI debuggers and tips for debugging React and Redux:
https://blog.isquaredsoftware.com/2021/06/presentations-debu...
I also have a prior post where I gave some general debugging tips, and wrote up several "war stories" of weird and difficult problems I've debugged:
https://blog.isquaredsoftware.com/2019/01/blogged-answers-de...
You mentioned "trace", and I'm not sure if you're referring to "trace a request as it gets passed through multiple services", or just "trace data flow on the client side".
The other resource I can point you to: a couple months ago I joined https://replay.io , and we're building a time-traveling debugger for JavaScript apps.
The basic idea of Replay: Use our special browser to make a recording of your app, load the recording in our debugger, and you can pause at any point in the recording. In fact, you can add print statements to any line of code while debugging the recording, and it will show you what it would have printed every time that line of code ran!
See https://replay.io/record-bugs for the getting started steps to use Replay, and https://docs.replay.io/docs/examples-d25ae319114e4d109022458... for some videos and examples of using Replay to solve problems.
We're working on additional features to help with debugging apps - we already have the React DevTools integrated into our debugger, so you can inspect the component tree at any pause point, and over the last couple weeks I got the initial alpha implementation of Redux DevTools integration working as well. (Long-term, we'd like to integrate _all_ major framework-specific DevTools as well.)
Beyond that, we also spend a bunch of time helping teach people how to debug in general, specifically _because_ that's a thing that is so rarely taught.
If you've got questions about Replay, or just want to chat about debugging approaches, come by our Discord at https://replay.io/discord and say hi - we'd love to offer suggestions!
FWIW, given the number of presentations I've put together and articles I've written [0], and the amount of effort I've put into all that material over the years, I don't think my work qualifies as "blogspam".
But, if you feel the material in that slideset is too basic, I'm genuinely curious: what info about "debugging modern web apps" _are_ you looking for, in that case? If there's some particular topics or ideas that aren't well covered, I might be able to put together something that would help fill that gap.
I will add it to my bookmarks to recommend to new developers alongside the excellent Eloquent Javascript [1], which for all I know probably is missing some things between when it was written and now which this modern javascript tutorial seems to cover. Very cool!
For all its qualities, Eloquent JS is not a very beginner-friendly book. For a smoother learning curve, you might consider https://github.com/thejsway/thejsway.
Disclaimer: I wrote this book.
This site is IMO the best reference out there for modern JS/DOM fundamentals. It's concise, clear, consistent, accurate, and well-organized throughout, which is no mean feat for how many topics it covers.
It swaps to an ironic, sarcastic, in-jokey tone almost completely divorced from the previous sections that will leave much of the intended audience (people new-ish to programming) utterly confused by what is being said—or in this case, worse, what is intentionally not said. The effect of this self-absorbed style of teaching is so poor, I think, that that page actually damages the overall text in its current state.
Surely the point of a site like this shouldn't be shaped for the entertainment of experienced programmers, but to help less experienced programmers know what to do—and what not to do. They could still make it funny, just... not that.
A Modern JavaScript Tutorial - https://news.ycombinator.com/item?id=25333350 - Dec 2020 (292 comments)
https://javascript.info/ninja-code
I get it's a list of bad practices and it's kind of funny in an "inside joke" kind of way but if you're reading the site to learn JavaScript then you are probably not on the "inside" yet?
As funny as it is for those "in the know" would it be better as a list of "don't to X (bad examples) do Y instead (good examples)? As it is there are no good examples, just a cryptic joke.
I’ve actually set up Alfred such that when I type “j [search terms]” in to its search bar that it opens a new tab with that search in JavaScript.info because I was doing “site:JavaScript.info” in google so frequently.
Basically all the things you otherwise forget about or never need to worry about when writing production JavaScript. Yawn. I sound like a curmudgeon and I am: too many interviews I've been in that involved JavaScript felt like abstracted garbage. Nevertheless, good luck!
How people answer questions around promises in general often gives me a good idea of where they are at in their JavaScript journey.
In just a few minutes of reading, I got cleared up on a few things.
For reference, I dabble in Javascript just to do small things that are incidental to my main programming languages.
Install https://addons.mozilla.org/en-US/firefox/addon/traduzir-pagi... and let the learning begin.
Like JS, PHP has alot of old, outdated practices which aren't considered best practice anymore. Lots of this type of code will show up in search results in google when you search for solutions to common problems.
So I'd like to be able to hit Cmd P or Ctrl K or the like, enter "nullish" and then find the article on nullish coalescing op.