|
Another newbie question here - JavaScript code:
Please tell me what mind-numbingly obvious thing I'm missing so I can stop mumbling to my text editor.
|
# ? Dec 17, 2013 04:13 |
|
|
# ? May 31, 2024 08:20 |
|
Raskolnikov2089 posted:Another newbie question here - You need to escape the character. try JavaScript code:
|
# ? Dec 17, 2013 04:19 |
|
Strong Sauce posted:You need to escape the character. I found and tried a similar suggestion on Stack Overflow, but it still outputs as: JavaScript code:
|
# ? Dec 17, 2013 04:23 |
|
The apostrophe is one of those slanted ones that sometimes get replaced in word documents or whatever, because it "looks fancier". Either add that slanted one to the list, or use the char code for it. The apostrophe might be getting converted to a real apostrophe on save, which is effectively removing the fancy apostrophe from the list. Both of these should work: /[\.,-\/#!$%\^'&'\*;:{}=\-_`~()’]/g or this one if the character gets converted: /[\.,-\/#!$%\^'&'\*;:{}=\-_`~()\u2019]/g
|
# ? Dec 17, 2013 04:25 |
|
obstipator posted:The apostrophe is one of those slanted ones that sometimes get replaced in word documents or whatever, because it "looks fancier". Either add that slanted one to the list, or use the char code for it. The apostrophe might be getting converted to a real apostrophe on save, which is effectively removing the fancy apostrophe from the list. I just realized I copied it from Word. Ok I'll commence banging my head on the desk. Fun lesson. Thank you. Raskolnikov2089 fucked around with this message at 04:35 on Dec 17, 2013 |
# ? Dec 17, 2013 04:28 |
|
JavaScript code:
JavaScript code:
vvv That makes sense (and is kind of fascinating). thank you. Raskolnikov2089 fucked around with this message at 23:06 on Dec 29, 2013 |
# ? Dec 29, 2013 20:54 |
|
Raskolnikov2089 posted:
What "(typeof x === 'string' || 'number' || 'undefined')" really means to javascript is: "typeof x === 'string'" OR "'number'" OR "'undefined'" not: "typeof x === 'string'" OR "typeof x === 'number'" OR "typeof x === 'undefined'" like you wanted. It may seem intuitive to only have the one "typeof x ===" but consider if you wanted an if statement that was like: if (typeof x === 'string' || x) {...} Where you wanted it to be either "the typeof x is string" OR "x has a value", you wouldn't be able to do that if javascript assumed you meant "typeof x is string" OR "typeof x is x". piratepilates fucked around with this message at 21:06 on Dec 29, 2013 |
# ? Dec 29, 2013 21:03 |
|
Raskolnikov2089 posted:Is this a particular quirk of typeof, or am I just assuming javascript is a lot more intuitive than it actually is? There is one place where you can use a syntax similar to that in Javascript, and that is to give variables default values: var x = someOtherValue || "The default value"; If someOtherValue is "truthy" (so not false, undefined, null, 0, NaN, or empty string) x is set to that. If it is "falsy", it is set to "The default value".
|
# ? Dec 29, 2013 23:29 |
|
Raskolnikov2089 posted:
JavaScript code:
|
# ? Dec 29, 2013 23:41 |
|
Raskolnikov2089 posted:
Another way you can do this: JavaScript code:
|
# ? Dec 31, 2013 07:02 |
|
Wheany posted:There is one place where you can use a syntax similar to that in Javascript, and that is to give variables default values: If someOtherValue is undefined, it's an error and you get a big fat nothing. You could use window.someOtherValue to try to work around that, though.
|
# ? Dec 31, 2013 17:10 |
|
hedgecore posted:Another way you can do this:
|
# ? Dec 31, 2013 19:02 |
|
Munkeymon posted:If someOtherValue is undefined, it's an error and you get a big fat nothing. You could use window.someOtherValue to try to work around that, though. Kind of. If the variable hasn't been defined, then yes it's an error - however, if the variable exists but has the value undefined, it works fine. Notably, this works: JavaScript code:
|
# ? Jan 1, 2014 00:33 |
|
I'm trying to simply copy an array of arrays into an array using the example: teamRedVelArrays = velArraysBackup.slice(0); This doesn't seem to make my array of arrays change to the backup or vise-versa. Is it different for an array of arrays?
|
# ? Jan 2, 2014 17:32 |
|
LP0 ON FIRE posted:I'm trying to simply copy an array of arrays into an array using the example: I can't quite tell what you're trying to ask, but using slice like that makes only a shallow copy. To clone your array values (which are themselves arrays here), you'll need to make a recursive copy function.
|
# ? Jan 2, 2014 18:10 |
|
5TonsOfFlax posted:I can't quite tell what you're trying to ask, but using slice like that makes only a shallow copy. To clone your array values (which are themselves arrays here), you'll need to make a recursive copy function. What do you mean by shallow copy? Like it only copies the initial array and not the arrays inside of it? I originally had a recursive copy function that had the same issue I'm having now. Does it have to be two for loops, one inside the other for it to work? I just had something like: code:
Edit: I found a function that did it. I guess it's more complicated than I think it should be? code:
LP0 ON FIRE fucked around with this message at 19:17 on Jan 2, 2014 |
# ? Jan 2, 2014 18:29 |
|
LP0 ON FIRE posted:This doesn't seem to make my array of arrays change to the backup or vise-versa. Is it different for an array of arrays? can you be more specific with what you mean by this sentence? Maybe use an example with some code. When I read this it sounds like what you are saying is: code:
|
# ? Jan 2, 2014 23:19 |
|
LP0 ON FIRE posted:What do you mean by shallow copy? Like it only copies the initial array and not the arrays inside of it? I originally had a recursive copy function that had the same issue I'm having now. Does it have to be two for loops, one inside the other for it to work? A key thing about Javascript, (and a lot of other languages) is that objects only ever get assigned by REFERENCE. This is a key concept to understand. code:
That's what is called a deep copy, and results in completely independant objects/arrays, they don't share values.
|
# ? Jan 3, 2014 00:16 |
|
Maluco Marinero posted:A key thing about Javascript, (and a lot of other languages) is that objects only ever get assigned by REFERENCE. This is a key concept to understand. Thanks for your advice. I'm really unfamiliar with javascript and I'm so used to having methods to just duplicate or point to other objects. I find it incredibly odd that I must loop through it to do a deep copy instead of a built-in function. I'm having an issue with my script locking up sometimes, and I narrowed it down to calling a duplication method. I've tried lots that I've found online and they all have this problem. The last one I tried is this: code:
I just want to add that teamBlueVelArrays and teamBlueVelArraysBackup are defined as arrays in the beginning of my script like: teamBlueVelArrays = new Array(); Anything obvious that's wrong with this? I'm doubting it. Otherwise I guess it's something else wrong it my code that is a direct result of cloning these arrays.
|
# ? Jan 3, 2014 23:08 |
|
How big and how deep are these structures? Depending on the sorts of items in these structures, you may be better served by serializing then reading back in using JSON.stringify and JSON.parse (in recent browsers). Edit: You should almost never use new Array(). Just use a literal [].
|
# ? Jan 3, 2014 23:22 |
|
Check the error console (ctrl + shift + J in Chrome and FF) for more information on the error and what line it's coming from. If there's an undefined or null value in that array somewhere, it'll cause an error when checking this if: if( this[i].clone ) { since this[i] might not be defined, and you'll be trying to get the value of a key of an undefined thing, which makes it throw an error. An undefined can show up in an array if you define a later value to something, which I think might be what's causing this: var a = []; a[1] = 5; a[0] would be undefined, and cause that if() to throw an error.
|
# ? Jan 3, 2014 23:30 |
|
obstipator posted:Check the error console (ctrl + shift + J in Chrome and FF) for more information on the error and what line it's coming from. After a little investigation, it looks like this was it! I didn't have any primary definition of the velocity array backup indexes, and if they were ever used, then yup, no set values = freeze. It was so simple and I should have caught it, but it was never an issue before until I changed something in my code. Thanks 5TonsOfFlax posted:How big and how deep are these structures? It's an array with an array inside every index at a set number of indexes. So I guess 2 levels? About new Array() vs []: isn't defining [] mean that it's sort of immutable and new Array() mutable?
|
# ? Jan 4, 2014 00:06 |
|
new Array() and [] mean the exact same thing, but the latter is what you'll more commonly see.
|
# ? Jan 4, 2014 00:09 |
|
Suspicious Dish posted:new Array() and [] mean the exact same thing, but the latter is what you'll more commonly see. Okay, so the difference between new Array() and [] (an array "literal") is just how they are written.
|
# ? Jan 4, 2014 00:39 |
|
LP0 ON FIRE posted:It's an array with an array inside every index at a set number of indexes. So I guess 2 levels? I'm glad you seem to have fixed your clone issue. It sounds like you only have arrays and primitives (no objects with functions or multiple references to the same items that you need to keep the same), so the JSON stringify parse method should work for you and be very fast. code:
|
# ? Jan 4, 2014 01:47 |
|
LP0 ON FIRE posted:Okay, so the difference between new Array() and [] (an array "literal") is just how they are written. Correct.
|
# ? Jan 4, 2014 07:50 |
|
LP0 ON FIRE posted:Okay, so the difference between new Array() and [] (an array "literal") is just how they are written. Semantically, yes. Usually. But not for performance (not an issue unless you have a shitload of arrays). http://stackoverflow.com/questions/931872/whats-the-difference-between-array-and-while-declaring-a-javascript-ar I just ran these tests in chrome: code:
code:
|
# ? Jan 4, 2014 18:16 |
|
LP0 ON FIRE posted:
Correct. > Array = function() { this.length = 42; } > x = new Array > x.length 42 > x = [] > x.length 0 [] is equivalent to the initial meaning of new Array(). (This was actually one of the clarifications in 5th edition of the spec, IIRC). (And using new Array hence might be slower since it needs to look up the global named Array, which may be tricky since the global scope in a web browser is nuts)
|
# ? Jan 4, 2014 19:06 |
|
OddObserver posted:[] is equivalent to the initial meaning of new Array(). It was an errata to the 3rd edition.
|
# ? Jan 4, 2014 21:57 |
|
I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example.
|
# ? Jan 6, 2014 23:36 |
|
gently caress the ROW posted:I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example. Not that I know of, and it's pretty easy to test in the console.
|
# ? Jan 7, 2014 02:54 |
|
gently caress the ROW posted:I've seen some discussion of this on stackoverflow, but is there any issue with JSON.stringifying an object that contains multidimensional arrays? Arrays of array_name[x][y] = ID for example. There shouldn't be any problems unless there are cyclical structures.
|
# ? Jan 8, 2014 09:52 |
|
Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone accomplished this? https://github.com/jawj/OverlappingMarkerSpiderfier#overlapping-marker-spiderfier-for-google-maps-api-v3 code:
|
# ? Jan 8, 2014 21:58 |
|
DholmbladRU posted:Looking to utlize the spiderfy which George MacKerron has developed. However I have one other requirement which is to load the map with all markers "spiderd" out by default. I can mimic this by using javascript to click on the markers, but there has to be another way by using the spiderfy code. Has anyone accomplished this? I use OMS and it's pretty great but it can't be set to auto spiderfy. I've seen it come up at the project site before. This issue has a guy with an idea on how to fake it, consider trying that.
|
# ? Jan 9, 2014 00:08 |
|
PlesantDilemma posted:I use OMS and it's pretty great but it can't be set to auto spiderfy. I've seen it come up at the project site before. This issue has a guy with an idea on how to fake it, consider trying that. Oh OMS is great. I just have some ridiculous requirement from this customer.. Thanks for that link:)
|
# ? Jan 9, 2014 03:39 |
|
I'm trying to use Select2 to select/submit multiple stock symbols at a time. I have a JSONified Python dictionary, stringified, that I can load into my HTML template. It looks something like this:JavaScript code:
|
# ? Jan 10, 2014 04:40 |
|
Why is each object not surrounded by curly braces? As you have it, this is one object with a giant pile of name-value pairs.
|
# ? Jan 10, 2014 04:48 |
|
...Oh Sorry, I'm not used to JSON. What I do at the moment is take a massive array and create an <option> tag for each element, which slows everything the gently caress down. I was hoping to use Select2's data functions to speed that up, but I may be a little lost.
|
# ? Jan 10, 2014 04:52 |
Pollyanna posted:...Oh Sorry, I'm not used to JSON. What I do at the moment is take a massive array and create an <option> tag for each element, which slows everything the gently caress down. I was hoping to use Select2's data functions to speed that up, but I may be a little lost. In your template, assign it to a javascript variable: code:
|
|
# ? Jan 10, 2014 04:55 |
|
|
# ? May 31, 2024 08:20 |
|
Unfortunately, it looks like Python's "translate to JSON" dealio causes a bit of a problem: all the keys are turned to strings, when I need them to be flat-out variables. e.g.:code:
code:
code:
|
# ? Jan 10, 2014 05:39 |