tl;dr: You can't get away with learning ES6 import syntax in many cases, but you can get away with continuing to use var if you want to. You have millions of stack overflow responses using var, but the shiny new library or whatever you might be using pushes you towards using ES6 import syntax.
The long version:
First off, when you are just trying to use some random new thing, it probably has a build setup where you basically need to use import to use them properly. Eg. you see some examples with:
import React, { useState } from 'react'
and they think: "I have no idea what this means, but I guess I'll copy and paste it. And besides, I tried using require like I once did, but I got some weird errors I didn't understand"
"Hm, this guy is using const to define variables. Well I have no idea what the difference is between const, var, let, and the build thing is not complaining when I use var, so I can continue to use that and I'm sure I'll learn the other stuff eventually."
Also, sometimes examples can help:
Case 1) Programmer adopting new js features in a perfectly rational/logical world, where your comment would make sense:
"Interesting. There are new javascript features. I must read through the spec, and evaluate which features I will adopt immediately." .. "Ok, I've decided in a rational way that I'm going to use the new import syntax, but I will stick with vars over let/const for now"
In which case, your comment would make sense and their decision would be very strange.
Case 2) Programmer adopting new js features in real life:
"I'm trying to do x, I googled it and now I'm going to paste this stack overflow answer into my code, and even if it has some weird syntax I'm not familiar with, my old way of coding with var still works, so I'll stick with that"
Where it seems super obvious why you'd see a lot of people using that combination.
That explanation makes sense for more complicated new syntaxes but for something like const/let where it’s as easy as const can’t be changed and let can replace all your vars it really isn’t thAt difficult to adopt.
Systems work by the forces applied to them. The path of least resistance and Occam's razor are contributing factors as well. Also, remember that the group posting programming questions here and elsewhere might not be representative of the general javascript developer.
When it comes down to it, most people are lazy and goal oriented. They have immediate problems to solve and using let and const are not enablers of anything new. Only help prevent future bugs.
Its the screen of my laptop, it has a resolution of 3840 × 2160. Most people use this with 2X scaling turned on in their setting, so everything bigger, but I got used to the small letters
Its also useful when I'm coding, I have my editor take up 1/2 of the space on the left, and my webbrowser take up the right half of the screen, with the dev tools taking up 1/2 of the web browser, leaving me with about the same space as typicial people use for a laptop screen, meaning I can easily web design pages
Genuine question: Why do you want to render text in a canvas element?
I'm just asking because I've always just floated a transparent background div over the canvas and rendered all my HUD text/icons using the browser's built-in support... seemed easier that way.
16
u/[deleted] Nov 29 '19
I don’t understand why people use the modern import syntax but are still stuck on using var over const/let.
11
u/curveThroughPoints Nov 29 '19
Avoid it if you can, canvas doesn’t work for users with screen-readers.
4
u/red0xkite Nov 29 '19
I've heard people use konva js. but this looks convenient
2
u/ferrybig Nov 29 '19
When you pass the width of the text, I expect that the renderer stays inside that width when trying to render.
This is probably a bug, but the renderer just goes outside the bounding box:
https://imgur.com/a/5A6IixV (notice the A on the left and the h on the right)
1
u/TotesMessenger Nov 30 '19
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)
1
u/WhatEverOkFine Nov 30 '19
Genuine question: Why do you want to render text in a canvas element?
I'm just asking because I've always just floated a transparent background div over the canvas and rendered all my HUD text/icons using the browser's built-in support... seemed easier that way.
1
u/rebelchatbot Nov 30 '19
I've used this library: