|
Strong Sauce posted:where whatever code in those functions are determined by the response time of the IO being called. then yes, i agree, and that is essentially what i said.
|
# ? Feb 11, 2019 07:10 |
|
|
# ? May 16, 2024 18:19 |
|
Tip posted:It's the top answer on stack overflow. Oh yeah, a stack overflow question and answer from 2010. That’s probably good JavaScript advice in TYOOL 2019. quote:using the Date object is just an overkill, and should be avoided since the ISO-8601 format is not widely supported -yet-, quote:Hint: Try it on IE8 or below, and even in old Firefox versions, it simply will not work..
|
# ? Feb 11, 2019 14:00 |
|
Moment is mutable all the way. If I have to use moment I'm in the habit of cloning the object before mutating because of that. It's really frustrating to work with .
|
# ? Feb 11, 2019 15:08 |
|
There is an immutable version of moment called Luxon.
|
# ? Feb 11, 2019 15:42 |
|
Chenghiz posted:There is an immutable version of moment called Luxon. Thanks for that, I managed to update a bit of my NYSE work to now actually work in other timezones. It is rather unfortunate that neither Moment or Luxon appear to be able to provide seconds-past-the-epoch local to a timezone. I guess it's a bogus entity but it is a rather popular one. I need to basically work in seconds-past-the-epoch in NYT anywhere in the world, but the APIs only support UTC underneath.
|
# ? Feb 11, 2019 18:22 |
|
FSMC posted:I pretty sure I would have used a for loop if it wasn't for the warning from eslint against using for loops. Are you sure it's not a warning about using for in loops? Those have some behavior that people find surprising, so a lot of people think they shouldn't be used, and, now that we have for of which has less surprising behavior, they're mostly right.
|
# ? Feb 11, 2019 20:41 |
|
smackfu posted:Oh yeah, a stack overflow question and answer from 2010. That’s probably good JavaScript advice in TYOOL 2019. I was just answering your question, "how do you even come up with that?" Your junior dev googled it and used the top answer on Stack Overflow. I wasn't saying, "it's the top answer on stack overflow, therefore the most correct!"
|
# ? Feb 11, 2019 22:18 |
|
Tip posted:I wasn't saying, "it's the top answer on stack overflow, therefore the most correct!" Didn’t think that at all, I was just rolling my eyes at the whole stack overflow page. Advice not to use a standard does not age well.
|
# ? Feb 12, 2019 02:41 |
|
Tip posted:I was just answering your question, "how do you even come up with that?" Your junior dev googled it and used the top answer on Stack Overflow. You cannot downvote without 125 reputation!
|
# ? Feb 12, 2019 03:37 |
|
Apparently date-fns is all the rage though I haven’t tried it myself yet.
|
# ? Feb 12, 2019 12:43 |
|
Anony Mouse posted:Apparently date-fns is all the rage though I haven’t tried it myself yet. It's nicer than moment but it doesn't do time zone conversions or durations, so not much use if you need those things.
|
# ? Feb 12, 2019 14:35 |
|
geeves posted:You cannot downvote without 125 reputation! Also, that time you tried to make a post with a better answer, they immediately closed it as a duplicate and redirected people to the bad answer. MrMoo posted:Thanks for that, I managed to update a bit of my NYSE work to now actually work in other timezones. It is rather unfortunate that neither Moment or Luxon appear to be able to provide seconds-past-the-epoch local to a timezone. I guess it's a bogus entity but it is a rather popular one. Luxon and Moment are both internally based on an epoch timestamp. All the time zone handling is purely for parse-to-timestamp and parse-from-timestamp purposes. JavaScript code:
|
# ? Feb 13, 2019 05:32 |
|
I'm working on a navigation/management page for some of my AWS resources. I had this code chunk working properly but our CSS guy went and made some changes and now its broken and I have no idea why. It looks like all the source files are the same as well as the div ids and the javascript, but when I run this chunk of code with the array data of [0: "crm", 1: "cs", 2: "elm", 3: "es", 4: "fscm", 5: "hcm", 6: "ih"] it returns an error. Essentially, I am querying an S3 bucket for a list of folders and I want to have each folder added as an option to the select. It worked find before so I'm not sure why it's broken now. code:
code:
code:
SnatchRabbit fucked around with this message at 20:44 on Feb 13, 2019 |
# ? Feb 13, 2019 18:56 |
|
SnatchRabbit posted:I had this code chunk working properly but our CSS guy went and made some changes and now its broken and I have no idea why.
|
# ? Feb 14, 2019 15:36 |
|
I'm fiddling around with building a media player in Electron, but short of the <video> attribute, I don't see any way of rendering video. While <video> is great and all, there are a boatload of formats and codecs that won't play in it. I can easily bundle in a copy of ffplay, which handles almost universal playback no problem, but the app launches in a separate window when run from childProcess.exec. That's to be expected but it's not what I want. Is there a way I can, I don't know, hide the child process and copy it's output frame-by-frame into my app? Or nest the process inside Electron somehow? The best solution I've been able to find so far is transcoding it on the fly to a format that <video> supports, but that's not something I'd like to do. Anyone have any suggestions?
|
# ? Feb 16, 2019 03:43 |
|
huhu posted:Sounds like you're not using source control. Why are you not using source control? I just started developing on GitHub as an individual and holy smokes where has this workflow been my whole life. I've discovered the concept of "branch per feature", which basically lets me break my project's code or entire API in ten or a hundred different ways at once, independently, without having to hesitate or worry about what breaking it one way will mean and how long it will delay me from working on any other features while it's broken. No, with GitHub I can just start a new branch any time and break the code to pieces just to experiment. I can access a non-broken copy that works any time just by switching the selected branch to the main unbroken one. The transition is hilariously smooth too. Just select a version (each representing a potential feature or rewrite direction) from the dropdown in GitHub desktop and instantly all the correct files teleport into place in your file system. I don't even have to close out Chrome, Chrome debugger, or my python host when this happens; they all see the correct codebase of whatever code branch I click on the instant I decide to change what I'm working on.
|
# ? Feb 16, 2019 04:05 |
|
Dumb Lowtax posted:I just started developing on GitHub as an individual and holy smokes where has this workflow been my whole life. I've discovered the concept of "branch per feature", which basically lets me break my project's code or entire API in ten or a hundred different ways at once, independently, without having to hesitate or worry about what breaking it one way will mean and how long it will delay me from working on any other features while it's broken. No, with GitHub I can just start a new branch any time and break the code to pieces just to experiment. I can access a non-broken copy that works any time just by switching the selected branch to the main unbroken one. If you really want fuckin' magic, start playing around with Github Actions or other CI (Continuous Integration) platforms like Travis CI or Circle CI. You can do stuff like have version numbers and changelogs automatically generate from git commits, have tests automatically run whenever branches get updated with results posted to pull requests, or even have code automatically bundle and deploy to a server whenever master gets updated without having to do anything manually. Also, if you start experimenting with the git command line, make sure to look at git add -p (lets you add only part of a changed file instead of the whole thing) and git rebase -i (lets you play with the history of local commits, so you can do stuff like take a bunch of commits named "WIP changes" and merge them into a single one). Roadie fucked around with this message at 05:16 on Feb 16, 2019 |
# ? Feb 16, 2019 05:14 |
|
I've been using [...Array(x)] as a hacky way to initialize empty arrays but this doesn't work in typescript. Is there a better way?
|
# ? Feb 16, 2019 17:25 |
|
Array(x).fill(undefined) Dunno if it will actually work with undefined as the arg but I don't see why it wouldn't.
|
# ? Feb 16, 2019 17:59 |
|
Obfuscation posted:I've been using [...Array(x)] as a hacky way to initialize empty arrays but this doesn't work in typescript. Is there a better way? edit nm
|
# ? Feb 16, 2019 18:00 |
|
necrotic posted:Array(x).fill(undefined) It does work, thanks.
|
# ? Feb 16, 2019 18:16 |
|
I'm trying to make an object with default data members that the constructor can override if it likes. Something like this:code:
I'm sure there's something I could do by making the function signature complex as hell but I want to avoid making it unreadable; the point is to clearly show what data members the object expects to have. I also, of course, want to avoid typing out all the keys again like this: code:
|
# ? Feb 17, 2019 04:30 |
|
Dumb Lowtax posted:I'm trying to make an object with default data members that the constructor can override if it likes. Something like this: Tired phone posting, but something like this maybe? JavaScript code:
Lumpy fucked around with this message at 05:36 on Feb 17, 2019 |
# ? Feb 17, 2019 05:28 |
|
Dumb Lowtax posted:I also, of course, want to avoid typing out all the keys again like this: JavaScript code:
|
# ? Feb 17, 2019 06:52 |
|
Can't compile it with anything, this code is for students and it's best if we stick to raw JavaScript.
|
# ? Feb 17, 2019 07:53 |
|
Does anyone know why the arguments object is empty there? Maybe es6 object destructuring syntax in parameters is like a new and weird part of the language, and they're phasing out the arguments keyword anyway so maybe they just didn't bother making the two things work together?
|
# ? Feb 17, 2019 08:32 |
|
Isn’t arguments more like an array than an object?
|
# ? Feb 17, 2019 14:37 |
|
Yes, I'd avoid writing anything like constructor (args) { ... }, because it confuses matters by giving the first entry in the arguments array (well, array-like object) the name args. Anyway: JavaScript code:
|
# ? Feb 17, 2019 14:54 |
|
Dumb Lowtax posted:Does anyone know why the arguments object is empty there? Maybe es6 object destructuring syntax in parameters is like a new and weird part of the language, and they're phasing out the arguments keyword anyway so maybe they just didn't bother making the two things work together? This isn't to do with object destructuring, it's more to do with the default parameter syntax. The arguments object you get automatically in any function is apparently derived from what the caller originally passes in, not from what your default parameter syntax creates. JavaScript code:
Doom Mathematic fucked around with this message at 16:05 on Feb 17, 2019 |
# ? Feb 17, 2019 15:09 |
|
Doom Mathematic posted:This isn't to do with object destructuring, it's more to do with the default parameter syntax. The arguments object you get automatically in any function is apparently derived from what the caller originally passes in, not from what your default parameter syntax creates.. Ah, makes sense. Thanks!
|
# ? Feb 17, 2019 18:32 |
|
On the other hand it feels like object destructuring syntax is kind of useless if there's no clean way to do the above. Why even add something like default function arguments to es6 if you can't use the new syntax with it? Why not make it possible to capture the arguments object *after* the default arguments are applied, since it's still common to want a guaranteed way of listing them all. Such as in my use case above. Happy Thread fucked around with this message at 23:09 on Feb 17, 2019 |
# ? Feb 17, 2019 23:06 |
|
Right now the best option seems to be the following. It completely omits object destructuring in parameters, which is really odd since it seems like that syntax was pretty much made for this situation and yet can't do the most useful thing. It also sucks because it's harder for the reader to immediately see what the constructor wants.code:
|
# ? Feb 17, 2019 23:09 |
|
Destructioring an object with defaults doesn't change the right hand side. Arguments is a reference to what the user passed in, which isn't being modified.
|
# ? Feb 17, 2019 23:48 |
|
The "right" answer for this kind of thing is the class property stuff with default values, anyway, which is stage 3 and only isn't in browsers yet because tc39 delayed it to also include private properties at the same time. Like, "no build step" to not overwhelm students is well and good, but at some point you have to take into account the "making half of the stuff in the Javascript world work in a not-ridiculous way requires a build step because of browser incompatibilities or stuff that isn't rolled out yet" problem.
|
# ? Feb 18, 2019 00:09 |
|
necrotic posted:Destructioring an object with defaults doesn't change the right hand side. Arguments is a reference to what the user passed in, which isn't being modified. Destructuring defaults is also excellent to help avoid null and undefined. Some JS devs want to argue about not having to use types, etc. in their code because it makes it too verbose and unclean, yet write code full of if / else malarkey checking for null values. If JS or TypeScript can start implementing the "?." (I forget its formal name) for null safety like Kotlin, I'd be very happy.
|
# ? Feb 18, 2019 00:16 |
|
geeves posted:If JS or TypeScript can start implementing the "?." (I forget its formal name) for null safety like Kotlin, I'd be very happy. That's in stage 1, and there's a Babel plugin for it.
|
# ? Feb 18, 2019 00:18 |
|
Dumb Lowtax posted:Right now the best option seems to be the following. It completely omits object destructuring in parameters, which is really odd since it seems like that syntax was pretty much made for this situation and yet can't do the most useful thing. It also sucks because it's harder for the reader to immediately see what the constructor wants. For the use case you described, there is no need to destructure the incoming options object, either in parameters or otherwise. I'm actually a bit puzzled as to why you prefer this solution over the one I suggested. Why two Object.assign calls? Why not keep the defaults as a distinct object? Another variant: JavaScript code:
|
# ? Feb 18, 2019 00:26 |
|
Don't worry I did it your way Doom, just had a memory blip about how it was. Except I threw those defaults in as local to the constructor just to keep it all contained.
|
# ? Feb 18, 2019 01:35 |
|
Roadie posted:That's in stage 1, and there's a Babel plugin for it.
|
# ? Feb 18, 2019 02:53 |
|
|
# ? May 16, 2024 18:19 |
I want to use Notifications in my site, but some dumb script is overwriting the Notification object as defined by the browser. What can I do about this if I can't remove the script?
|
|
# ? Feb 18, 2019 21:23 |