|
Subjunctive posted:In that case [w.IDNum][0][1] should be "groceryStore.jpg", if I'm understanding your post correctly, so I suspect you're not interpreting the error correctly, or else we're misunderstanding each other about what to print here. See my edit. It reports it as undefined, then I click the error button again in inspector and it shows that they are defined as ["default", "groceryStore.jpg"]. No interval is running. edit: It looks like clicking that error button unfolds something below my console.log and shows what it is, but below that it says undefined. This is what it looks initially before clicking the red error button again: LP0 ON FIRE fucked around with this message at 16:46 on Jul 22, 2014 |
# ? Jul 22, 2014 16:40 |
|
|
# ? Jun 3, 2024 14:17 |
|
The value "undefined" is the value returned by your call to console.log(). console.log() doesn't return a value; it prints a value out to the console, then returns nothing (i.e. undefined). Try typing "keyTimesAndImages[0]" at the console, all on its own.
|
# ? Jul 22, 2014 16:48 |
|
qntm posted:The value "undefined" is the value returned by your call to console.log(). Thanks. I get ["default", "groceryStore.jpg"]
|
# ? Jul 22, 2014 16:53 |
|
Is this while you're stopped at the error, or later? If that's the value when it's evaluating that expression, I'm stumped.
|
# ? Jul 22, 2014 16:55 |
|
It's not like a breakpoint that stops at the error. The page run continues to run normally even if times start. Specifically it says: TypeError: 'undefined' is not an object (evaluating 'keyTimesAndImages[window.IDNum][0]') And I just tested, even if window.IDNum doesn't change later down the line, I still get the error. It shouldn't have mattered anyway though. Update - I test for both of these before evaluating and it works without errors: code:
LP0 ON FIRE fucked around with this message at 17:40 on Jul 22, 2014 |
# ? Jul 22, 2014 17:03 |
|
Is there a reason to use == instead of ===? People reference Doug Crawford's opinion and I've seen arguments for always using ===, but I don't know about edge cases.
|
# ? Jul 22, 2014 17:51 |
|
Analytic Engine posted:Is there a reason to use == instead of ===? Definitely! This is very important. Just look up the differences. http://stackoverflow.com/questions/523643/difference-between-and-in-javascript The case being if you're doing a strict vs non-strict comparison. quote:JavaScript has both strict and type-converting equality comparison. For strict equality the objects being compared must have the same type and: It's also important to mention that === is only true if the operands are the same type. == is used for abstract comparisons and converts it to the same type before making a comparison. LP0 ON FIRE fucked around with this message at 18:25 on Jul 22, 2014 |
# ? Jul 22, 2014 18:18 |
|
Analytic Engine posted:Is there a reason to use == instead of ===? Use === when you want to make sure the operands are the same type. If you don't care whether a variable holds a 2 or a "2", you can use ==. Even then, I would probably use something like if(Number(variable) === 2)
|
# ? Jul 22, 2014 18:49 |
|
LP0 ON FIRE posted:Definitely! This is very important. Just look up the differences. http://stackoverflow.com/questions/...d-in-javascript Wheany posted:Use === when you want to make sure the operands are the same type. If you don't care whether a variable holds a 2 or a "2", you can use ==. Thanks, that backs up what I've read and tested out. I'm trying to improve my Javascript habits and it sounds like thinking of === first is a good one. I'll use == for specific cases like user input and reading text files. Wheany posted:Even then, I would probably use something like if(Number(variable) === 2) Didn't think of this, even more specificity could come in handy.
|
# ? Jul 22, 2014 19:18 |
|
Analytic Engine posted:Didn't think of this, even more specificity could come in handy. Switch-case uses strict comparison, so switch(Number(variable)) is probably the most common use case for me, actually
|
# ? Jul 22, 2014 20:16 |
|
Wheany posted:Switch-case uses strict comparison, so switch(Number(variable)) is probably the most common use case for me, actually Cool, I also didn't know about === in switch ( ). And after testing, it looks like leaving out an equality condition in if ( ) will default to trying ==. code:
Analytic Engine fucked around with this message at 23:27 on Aug 18, 2014 |
# ? Jul 22, 2014 20:53 |
|
code:
EDIT: Nevermind, got it. Space Kablooey fucked around with this message at 21:03 on Jul 22, 2014 |
# ? Jul 22, 2014 20:55 |
|
^^^ Dunno, but why would you want to? -0.0 is different from 0.0. Analytic Engine posted:Cool, I also didn't know about === in switch ( ). since it's always true for objects, regardless of what their values are: code:
|
# ? Jul 22, 2014 21:02 |
|
Analytic Engine posted:Cool, I also didn't know about === in switch ( ). Here's a weird old trick to converting a variable to boolean: !!variable Also for setting a default value for a variable, you might see somthing like this: function(setting){ var value = setting || "default value"; }
|
# ? Jul 22, 2014 21:40 |
|
OddObserver posted:== to what? And at any rate, it's not comparing it with anything; it's using a Boolean conversion. That's actually observable, You're right, I was confused. Never tried boolean conversion before. I had thought these lines were equivalent: code:
Wheany posted:Here's a weird old trick to converting a variable to boolean: !!variable Ha, I saw that when starting Javascript and had no clue. Some tutorials launch right in. Analytic Engine fucked around with this message at 22:07 on Jul 22, 2014 |
# ? Jul 22, 2014 21:58 |
|
Subjunctive posted:That's not my recollection, and I think I was the first person to implement JS exceptions. JScript had a bug where it created the variable in the enclosing function's scope, rather than one that matched the duration of the catch block, which I think is the opposite of what you're describing, but exceptions were always specified to create a new scope chain entry with the identifier bound. I remember it being an off-hand remark by some engineer in #whatwg, #jsapi, or on a mailing list like es-discuss or whatwg. Sorry I don't have a better reference, and my limited attempts to look through the archvies didn't pull up anything.
|
# ? Jul 23, 2014 05:28 |
|
I've been asked to provide a page that generates MD5, SHA1, DES, and 3DES keys to be used in securing a bunch of systems. Is this as bad of an idea as it sounds? Is there a safe method to generate these keys in-browser in a secure way? I'm guessing I can use crypto-js to generate the keys and then pass Math.random values into it or something for entropy, but is this actually going to be safe?
|
# ? Jul 23, 2014 14:27 |
|
revmoo posted:I'm guessing I can use crypto-js to generate the keys and then pass Math.random values into it or something for entropy, but is this actually going to be safe? My first guess is that Math.random is worthless for cryptography. My second guess is that maybe you could use mouse movements or something to gather entropy. But the number 1 rule w/r/t cryptography is "Never roll your own." Also you can't trust any client-provided values, you have to do the calculation server-side.
|
# ? Jul 23, 2014 14:35 |
|
Wheany posted:My first guess is that Math.random is worthless for cryptography. My second guess is that maybe you could use mouse movements or something to gather entropy. Your first guess is also my first guess. I can actually probably trust the client on this one because they are inputting a key for their personal device and they're permitted to override the generated value if they want. But I'm really not sure what a safe way to generate these keys would be, even it's even possible.
|
# ? Jul 23, 2014 14:38 |
|
Math.random is about as far from a CRNG as you can get. It's sometimes even worse than return 2; as it's sometimes an easy to predict PRNG that leaks state between pages.
|
# ? Jul 23, 2014 14:52 |
|
Well I left someone else make the decision and sign off on it, but basically what I ended up doing is seeding crypto-js with the output from seedrandom: https://github.com/davidbau/seedrandom
|
# ? Jul 23, 2014 16:22 |
|
Are there any tools for traversing a hyperlinked JSON API? For example, say an API request to http://0.0.0.0/api/moms/ returns: JavaScript code:
JavaScript code:
JavaScript code:
|
# ? Jul 23, 2014 17:10 |
|
My general experience with things (not in JS) that try to magically handle HATEAOSy APIs is that they don't end up doing anything useful. The lack of standards means that unless you're designing the API to fit what the library wants, configuring the library is at least as much work as just rolling something yourself would be, and you probably can't get away with eagerly fetching the graph (since that may involve a very large number of requests), so all you really want is some helper methods to make it easy to resolve links.
|
# ? Jul 23, 2014 17:27 |
|
Plorkyeran posted:HATEAOSy APIs Gesundheit!
|
# ? Jul 23, 2014 17:58 |
|
Wheany posted:Here's a weird old trick to converting a variable to boolean: !!variable The problem with that second one is that there are lots of values in Javascript that are false-y besides False. There are scenarios where you might want to pass one of them as an argument and not have the function provide a default value. You could use the slightly more verbose and ungainly: code:
The Insect Court fucked around with this message at 09:17 on Jul 24, 2014 |
# ? Jul 24, 2014 06:23 |
|
The Insect Court posted:The problem with that second one is that there are lots of values in Javascript that are false-y besides False. There are scenarios where you might want to pass an empty Object or Array or String as an argument and not have the function provide a default value. You could use the slightly more verbose and ungainly:
|
# ? Jul 24, 2014 07:59 |
|
Besides, if you look at the source code of some libraries, you will see that pattern used, so it's good to recognize it.
|
# ? Jul 24, 2014 08:20 |
|
It looks like using overflow:auto is throwing off my getBoundingClientRect() left and top properties, but it also behaves the same if I calculate an elements offset with a loop. I discovered this when I took away the line height of an article with a long image next to it set to float:right; the content underneath it settles right below the article and not the image. So I wrapped it in a div and added overflow:auto; code:
But it causes whatever depends on using getBoundingClientRect() to be offset upwards from where they should be. In my case it's buttons that are further down the page. Maybe the solution is to use something other than the wrapper div with overflow:auto, but I'm not quite what that would be. Update - Figured this out finally. The image next to it was part of a slideshow that changed. The y position of the buttons below were basing it off the height of the shortest image. So I ended up giving the div a height and will probably base it off the tallest image eventually. LP0 ON FIRE fucked around with this message at 14:39 on Jul 28, 2014 |
# ? Jul 25, 2014 16:30 |
|
Is this the right place for obscure Node questions? I need to watch a directory for new files, including files that might be in a subdirectory. I've tried 3 modules: https://github.com/mikeal/watch https://github.com/yuanchuan/node-watch https://github.com/bevry/watchr but they all have the same problem: if I copy a directory that contains a file into the watch folder, they only pick up on the "new directory" event, and ignore the file. If I create the directory first, then copy the file into it, both events get picked up fine. But I need to copy folders that already contain files into my watch directory and have them all picked up at once. Any ideas? Is this the kind of thing that I should raise an issue about on github? (kinda scared because I've never done that) Or should I give up on the modules and write my own "walker" function that gets called periodically?
|
# ? Jul 25, 2014 20:07 |
fuf posted:Is this the right place for obscure Node questions? In the "created" handler that picks up the "new dirctory" event, can't you just list the files in that new directory and do whatever you want with them?
|
|
# ? Jul 25, 2014 20:19 |
|
Oh hey I guess I could. I kept hesitating between whether to use a "watcher" or a "walker", but I guess what I could do is watch for new directories, then walk through them to get the files. Life would be a lot easier if the watchers just picked up every actual change though. Anyway thanks
|
# ? Jul 25, 2014 20:38 |
|
I've been staring at this for the last 1/2 hour trying to figure out where my syntax error is.code:
Raskolnikov2089 fucked around with this message at 03:00 on Jul 26, 2014 |
# ? Jul 26, 2014 02:53 |
Raskolnikov2089 posted:I've been staring at this for the last 1/2 hour trying to figure out where my syntax error is. You're missing a closing parenthesis on the line with the if statement
|
|
# ? Jul 26, 2014 03:00 |
|
Ughhhhh okay, thats enough for the night. Thank you.
|
# ? Jul 26, 2014 03:03 |
Raskolnikov2089 posted:Ughhhhh okay, thats enough for the night. Is your debugger not giving you useful error messages? All I did was paste it into jsfiddle, open the Firebug console, hit Run, and it gave me a very clear error message:
|
|
# ? Jul 26, 2014 03:27 |
|
That's actually more helpful than chrome, which gives me Uncaught SyntaxError: Unexpected token { Which told me there was a syntax error which is usually enough, but the firebug message would have been a lot more helpful given how burnt out I was on staring at a pc screen.
|
# ? Jul 26, 2014 06:08 |
|
I've done more javascript over the past week than in the rest of my life combined, and this sort of thing is driving me insane. I was two hours with this piece of jQuery, which would be plain skipped over by the debugger rather than even causing an error. As in, the debugging cursor would jump directly from the first line here to the further code below.code:
|
# ? Jul 26, 2014 19:02 |
|
Newf posted:I've done more javascript over the past week than in the rest of my life combined, and this sort of thing is driving me insane. I was two hours with this piece of jQuery, which would be plain skipped over by the debugger rather than even causing an error. As in, the debugging cursor would jump directly from the first line here to the further code below. If the $(".ItemList > a") selector doesn't find any elements, then each won't call the function. Were you stepping over or into?
|
# ? Jul 26, 2014 20:33 |
|
http://jsfiddle.net/2duEv/code:
Maybe I don't understand for loops as well as I thought I did.
|
# ? Jul 26, 2014 21:55 |
|
|
# ? Jun 3, 2024 14:17 |
|
Raskolnikov2089 posted:http://jsfiddle.net/2duEv/ When you splice, you are moving the other elements backward. So you have this pattern: code:
code:
code:
code:
|
# ? Jul 26, 2014 22:08 |