|
A question about async and callbacks. I get handing the async method a callback and that's not a problem. I can handle something like a Google Analytics API query a callback and the google library calls my function once the request is complete, great! But how does the google api actually manage the callback if its own process is asynchronous? At the point where the api sends off a method call to the internet, what process does it do to wait for the result and synchronously manage the callback?
|
# ? Apr 12, 2015 18:21 |
|
|
# ? Jun 5, 2024 05:39 |
|
JavaScript code:
|
# ? Apr 12, 2015 19:26 |
|
Ahz posted:A question about async and callbacks. I'm not 100% sure what you're asking. At the very bottom level you're probably going to find an XMLHttpRequest. Hugely simplified: JavaScript code:
As for what happens inside XMLHttpRequest, itself, it's a JavaScript builtin, so a black box really.
|
# ? Apr 12, 2015 21:17 |
|
qntm posted:I'm not 100% sure what you're asking. At the very bottom level you're probably going to find an XMLHttpRequest. Hugely simplified: Yeah I understand what you're saying. I guess I'm looking further down the rabbit hole into the black box.
|
# ? Apr 13, 2015 19:42 |
|
The black box is pretty simple, at least the basic architecture. If you want to understand how the JS event loop works internally, this presentation is a great introduction: https://www.youtube.com/watch?v=8aGhZQkoFbQ Edit: This is the tool he's using in the video to visualize the event loop. DimpledChad fucked around with this message at 21:13 on Apr 13, 2015 |
# ? Apr 13, 2015 21:08 |
|
How do you profile JavaScript (in-browser) for hotspots? I had some really slow-running code and I got it to acceptable with my spidey-sense but it would be nice to have some actual measurements to work with.
|
# ? Apr 14, 2015 02:17 |
|
Use the Profiler in Chrome DevTools. Load up the tab in DevTools, click Start, refresh your page and then hit stop when it's done loading..
|
# ? Apr 14, 2015 02:39 |
|
DimpledChad posted:The black box is pretty simple, at least the basic architecture. If you want to understand how the JS event loop works internally, this presentation is a great introduction:
|
# ? Apr 14, 2015 14:48 |
|
Kekekela posted:Wow, very helpful. I didn't realize how much of that I didn't know.
|
# ? Apr 14, 2015 16:11 |
|
ArcticZombie posted:Thanks, I solved the problem, but I can't understand why the first log has access to the object but the ones after it don't. We'd have to see the rest of your code. I can virtually guarantee the answer will be somewhere else in your code than what you've included in your post.
|
# ? Apr 17, 2015 07:12 |
|
I'm working on a page which serves as a dashboard for a desktop app, and it keeps itself up to date with an ajax request for some json that's running on a timer. The problem that I'm having is that the memory footprint of the browser is creeping up with every single call. It's slow, but this is the sort of page that might reasonably be expected to be open for hours at a time, and it'll be running on a mobile device. It's a super simple refresh inside the loop, JavaScript code:
Newf fucked around with this message at 13:08 on Apr 17, 2015 |
# ? Apr 17, 2015 12:36 |
|
Newf posted:I'm working on a page which serves as a dashboard for a desktop app, and it keeps itself up to date with an ajax request for some json that's running on a timer. In your example, you're calling applyUpdatesToPage immediately, is that what your actual code does? Because I don't think that would work, unless applyUpdatesToPage returns a function.
|
# ? Apr 17, 2015 13:01 |
|
Wheany posted:In your example, you're calling applyUpdatesToPage immediately, is that what your actual code does? Because I don't think that would work, unless applyUpdatesToPage returns a function. Sorry, yes, I do that every single time that I set a value to a function. The actual page sets the callback correctly and updates are applied.
|
# ? Apr 17, 2015 13:06 |
|
Hey all, Work is offering to pay for a conference to increase my awesomeness. Doing some basic googling I found JSConf and suggested that. If I'm mostly a backend guy who uses vanilla JS/JQuery when the need arises is this a good conference for me? I can pick things up pretty quickly and obviously a paid trip to JVille would be solid, but if I'm going to be out of my league for a lot of the conference I can find another one. Thanks!
|
# ? Apr 17, 2015 16:20 |
|
silentpenguins posted:Hey all, Do you mean JSConf US? According to their tickets page, it's sold out already. http://2015.jsconf.us/tickets.html That conference is super duper popular and sells out really quick.
|
# ? Apr 17, 2015 16:43 |
|
jkyuusai posted:Do you mean JSConf US? According to their tickets page, it's sold out already. http://2015.jsconf.us/tickets.html Cheaper tickets have sold out but the general admission Journey a few slots down is still for sale. Have you been?
|
# ? Apr 17, 2015 18:25 |
|
silentpenguins posted:Cheaper tickets have sold out but the general admission Journey a few slots down is still for sale. Have you been? Oh wow, totally missed that, my apologies. I haven't, but I've heard from some that have that they really enjoyed it. We've talked about doing it as a group some year since we're based in Tallahassee, but we always seem to forget come ticket time.
|
# ? Apr 17, 2015 19:42 |
|
So, I learned about Douglas Crockford's DEC64 and was thinking: Does Javascript actually require float (or double) specifically, or is it an implementation detail? Could someone make a standards compliant Javascript interpreter that used for example DEC64? Or does something in the standards say (or imply at least) that "0.1 + 0.2 == 0.3" must be false?
|
# ? Apr 18, 2015 11:58 |
|
Wheany posted:So, I learned about Douglas Crockford's DEC64 and was thinking: Does Javascript actually require float (or double) specifically, or is it an implementation detail? The ECMAScript standard says that number type is "primitive value corresponding to a double-precision 64-bit binary format IEEE 754 value." A javascript implementation using DEC64 would violate the ECMAScript standard.
|
# ? Apr 18, 2015 12:14 |
|
Welp, that's pretty conclusive.
|
# ? Apr 18, 2015 12:49 |
|
Wheany posted:Welp, that's pretty conclusive.
|
# ? Apr 18, 2015 19:22 |
|
it's a lot better that javascript required a consistent number type across implementations instead of letting implementors choose the number type they felt like using javascript only supporting one primitive number type is another matter
|
# ? Apr 20, 2015 00:12 |
|
comedyblissoption posted:it's a lot better that javascript required a consistent number type across implementations instead of letting implementors choose the number type they felt like using Seriously. The only way to make the "only one number type" situation worse would be letting the implementor decide what it is.
|
# ? Apr 20, 2015 12:17 |
|
Anyone know whether it's possible to transpile the JS in an HTML file from es6 to es5? Want to start using es6, but I prefer all the code in one file rather than editing the JS as an external file.
|
# ? Apr 21, 2015 19:16 |
|
ufarn posted:Anyone know whether it's possible to transpile the JS in an HTML file from es6 to es5? You could maybe probably hack it in with something like: code:
|
# ? Apr 21, 2015 19:29 |
|
Most transpilers work based on the type attribute of the script tag. It should just work.
|
# ? Apr 21, 2015 19:32 |
|
Suspicious Dish posted:Most transpilers work based on the type attribute of the script tag. It should just work.
|
# ? Apr 21, 2015 20:03 |
|
I've used Traceur with success in the past.
|
# ? Apr 21, 2015 21:30 |
|
ufarn posted:Hmm, babel (FKA e6toe5) just reads the HTML file and throws an error at the first line ($ babel index.html). Haven't found anything by googling either. Guess I could install all the transpilers I can find and try manually, but it does sound like a pretty basic feature. I think babel wants to work on out-of-line JS files, yeah. I can't blame them for not wanting to add HTML parsing to their workload. The runtime transpilers will work from <script> tag type, but I don't know of any that will statically rewrite HTML. Have I forgotten that Traceur does that?
|
# ? Apr 22, 2015 01:21 |
|
I was assuming the poster meant runtime transpiling. I imagine it's not too difficult to hook up html5lib to some transpiler though if you still want a build step. I don't see the benefit of wanting a single file and also having a build step though.
|
# ? Apr 22, 2015 04:15 |
|
Subjunctive posted:I think babel wants to work on out-of-line JS files, yeah. I can't blame them for not wanting to add HTML parsing to their workload. It seems weird that Traceur doesn't have a CLI open, when it can do it in runtime, but the docs don't seem to suggest a compile command not based on .js files. ufarn fucked around with this message at 12:02 on Apr 22, 2015 |
# ? Apr 22, 2015 12:00 |
|
Suspicious Dish posted:I was assuming the poster meant runtime transpiling. I imagine it's not too difficult to hook up html5lib to some transpiler though if you still want a build step. I don't see the benefit of wanting a single file and also having a build step though. You'd get slightly better load times on ES < 6 browsers right? I mean, if you're that worried about it, it'd be better to just stick to ES5 but whatever.
|
# ? Apr 22, 2015 17:14 |
|
If you want a build step, use one of the HTML minifiers that will auto-include source for you if it thinks it's worth it.
|
# ? Apr 22, 2015 18:09 |
|
I like ES6 features too much. I've just resigned myself to having a build step for anything I do for a browser and have worked on making that as easy and transparent as possible for myself.
|
# ? Apr 22, 2015 18:18 |
|
I'm an idiot.
huhu fucked around with this message at 01:24 on Apr 23, 2015 |
# ? Apr 23, 2015 01:07 |
|
Thermopyle posted:I like ES6 features too much. I've just resigned myself to having a build step for anything I do for a browser and have worked on making that as easy and transparent as possible for myself. What's your toolchain like? What do you use for your builds?
|
# ? Apr 24, 2015 05:01 |
|
The Wizard of Poz posted:What's your toolchain like? What do you use for your builds? Depends on the project. I tend to have one ongoing project that lasts months with a few small things scattered here and there. For simple needs, I have file watchers set up in my IDE (PyCharm/WebStorm) which automatically do my build stuff on each save. The following is what I'm using on my current big project, and I'll reevaluate the state of the art when I get to my next project. watchify -v --debug -t babelify js/main.js -o js/bundle.js I try my best to only use libraries from npm since, despite its shortcomings, is far far better than bower or any of that other stupid poo poo. If a library I really need isn't on npm, I'll likely just download it and bundle it myself. I also have npm set up to run the following when I run npm start. mochify --watch --transform [babelify --ignore node_modules] --plugin [proxyquire-universal] --recursive I've got that running in another terminal window. And then I've got a stupid livereload server running with grunt running in another terminal window. I'm not really happy with it because of reasons I can't think of right now...
|
# ? Apr 24, 2015 16:47 |
|
I'd like for a callback to be aware of whether or not this is the first time it has been called. My current solution works but I'd prefer to hide the firstRun toggle from the global scope.JavaScript code:
|
# ? Apr 24, 2015 18:01 |
|
Newf posted:I'd like for a callback to be aware of whether or not this is the first time it has been called. My current solution works but I'd prefer to hide the firstRun toggle from the global scope. There's probably several ways. Here's one: JavaScript code:
HappyHippo fucked around with this message at 18:27 on Apr 24, 2015 |
# ? Apr 24, 2015 18:21 |
|
|
# ? Jun 5, 2024 05:39 |
|
Newf posted:I'd like for a callback to be aware of whether or not this is the first time it has been called. My current solution works but I'd prefer to hide the firstRun toggle from the global scope. Factory? JavaScript code:
JavaScript code:
|
# ? Apr 24, 2015 18:28 |