|
Gordon Cole posted:Cool, so I guess all static analysis tools are completely useless. And what's the deal with compiler warnings?! It's not like a computer is going to find any problems with our code, so why even bother! The most important thing he is actually saying is "Global variables are totally cool and the more you use them, the better" Gordon Cole posted:The "only real problem" with leaving out semicolons that he mentions is actually a pretty big problem: This is my favorite part. I'd say that "always use semicolons" is a bit easier to remember and less error prone than "never use semicolons, except..."
|
# ? Dec 13, 2012 07:35 |
|
|
# ? Jun 8, 2024 07:26 |
|
akadajet posted:I was looking at GitHub's Javascript Styleguide and noticed this... Holy gently caress. I really don't know how else to respond to that. I've always though of JavaScript's optional semicolons as a poorly thought out feature that is best left ignored/pretending it doesn't exist. Suspicious Dish posted:JSLint is a piece of opinionated garbage. I mean, it has a goatse as its logo. Hahahah. I don't know how I've never noticed that before (not that I actually use JSLint as I find it to be pretty superfluous). e: http://mislav.uniqpath.com/2010/05/semicolons/ posted:Look at some obfuscated code; there are semicolons in there. Does it help readability? No, but what would really help is a lot of whitespace and original variable names. I get the point he's trying to make, but still... Optimus Prime Ribs fucked around with this message at 10:41 on Dec 13, 2012 |
# ? Dec 13, 2012 10:16 |
|
Optimus Prime Ribs posted:Holy gently caress.
|
# ? Dec 13, 2012 15:15 |
|
Mogomra posted:Is it even really a "feature" as much as it was one browser assuming that people writing JavaScript are mouth-breathing sub-humans, and then every other browser thinking they needed to do that too or else they'd break the internet?
|
# ? Dec 13, 2012 15:28 |
|
Plorkyeran posted:ASI was an intentional part of the original design of Javascript. It just wasn't quite done correctly since Eich only had a few days to hack together Javascript.
|
# ? Dec 13, 2012 15:47 |
|
Plorkyeran posted:ASI was an intentional part of the original design of Javascript. It just wasn't quite done correctly since Eich only had a few days to hack together Javascript. Leaving off semicolons was intended. ASI was a hack thrown in at the last minute. I like the idea of leaving off semicolons, but ASI is just too risky.
|
# ? Dec 13, 2012 15:54 |
|
Karthe posted:I'm in the middle of making a web-based "connect the colored, numbered dots to make a picture" game - think PathPix or Link-A-Pix. It's a simple thing at the moment, with all of the JS, CSS, and HTML contained within one HTML document. Things have been going well - I've got path validation figured out, as well as the method by which I can generate a playing field of variable size and then lay out a sequence of predetermined colored number points for the user to connect. I'd make an array of Objects referencing an array + meaningful info. When someone makes a new path from a previous point, push a new Object into the paths superarray with the elements you wish to keep etc. Have each object also store its index. Note: If you ever shift() the array you will need to update that reference.
|
# ? Dec 13, 2012 17:11 |
|
Wozbo posted:I'd make an array of Objects referencing an array + meaningful info. When someone makes a new path from a previous point, push a new Object into the paths superarray with the elements you wish to keep etc. Have each object also store its index. code:
IAmKale fucked around with this message at 19:25 on Dec 13, 2012 |
# ? Dec 13, 2012 18:13 |
|
No, more like:code:
ArrayPaths[1] is the next etc etc. E: I'm not gonna quote it all, but quote the Keys and you also have valid, serializable JSON object if you want to be able to send a saved state to someone else. Wozbo fucked around with this message at 19:46 on Dec 13, 2012 |
# ? Dec 13, 2012 19:43 |
|
I'm writing a javascript game and I want to use right click as a control. I can prevent the context menu from appearing by doingJavaScript code:
|
# ? Dec 13, 2012 21:07 |
|
HappyHippo posted:I'm writing a javascript game and I want to use right click as a control. I can prevent the context menu from appearing by doing IAmKale fucked around with this message at 21:30 on Dec 13, 2012 |
# ? Dec 13, 2012 21:27 |
|
So basically "click" won't register on right clicks, and I have to rely on "contextmenu" for right click events?
|
# ? Dec 13, 2012 21:57 |
|
HappyHippo posted:So basically "click" won't register on right clicks, and I have to rely on "contextmenu" for right click events?
|
# ? Dec 13, 2012 23:10 |
|
Karthe posted:You can determine what mouse button has been clicked on a mouse event, just check e.which == 3 for right-click (1 is left, 2 is middle). Yeah that's what I attempted to do but no luck, the event doesn't even fire so I don't get to that point. It seems to work if I just handle the contextmenu event and pass the event argument to the click event handler like this: JavaScript code:
|
# ? Dec 13, 2012 23:44 |
|
Gordon Cole posted:This is my favorite part of the linked article:
|
# ? Dec 14, 2012 00:34 |
|
Gazpacho posted:If Ext.util.CSS does not allow you to modify your static rules, it should allow you to copy them into runtime rules that you can modify (and would override the static ones through cascading). Ext.util.CSS worked perfectly. Thank you so much!
|
# ? Dec 14, 2012 00:35 |
|
JavaScript code:
IAmKale fucked around with this message at 21:35 on Dec 14, 2012 |
# ? Dec 14, 2012 21:33 |
|
edit: nvm.
|
# ? Dec 14, 2012 21:41 |
|
Post the rest of your function and some sample structure, recursion can be a bitch sometimes and I bet you its a subtle problem on the unwind. Easy way to do it: give me a JSON.stringify(foo) of what you do on the first call.
|
# ? Dec 14, 2012 21:44 |
|
Wozbo posted:Post the rest of your function and some sample structure, recursion can be a bitch sometimes and I bet you its a subtle problem on the unwind. Here's the entire function, as well as the object that I want to parse through with the recursive function: JavaScript code:
JavaScript code:
|
# ? Dec 14, 2012 22:02 |
|
Looking it over. First thoughts: Null and undefined aren't the same thing. I'd do this: if(objCellArray[cellID].next != null && objCellArray[cellID].next != undefined) for your checks. As for the second part, giving the parameters is what json.stringify would have done. You just included it at the top so I didn't need it again. EDIT AHHAHAH, heres your problem. put this: return getLastSegment(objCellArray[cellID].next, false); Totally overlooked it. When you unwind you aren't returning the value. E: Working code code:
code:
Wozbo fucked around with this message at 22:26 on Dec 14, 2012 |
# ? Dec 14, 2012 22:10 |
|
Oh man, that was my problem? But what does adding return to the recursive function call do? I thought I only needed to add return to the information I wanted to get back from the function.
|
# ? Dec 14, 2012 22:26 |
|
Think about this, when you return, what are you doing with the returned value? The second you go one level up, you have the result and promptly do nothing with it. You should return back up now that you have something meaningful. E: Code example code:
Simple example: code:
Wozbo fucked around with this message at 22:36 on Dec 14, 2012 |
# ? Dec 14, 2012 22:29 |
|
Wozbo posted:Think about this, when you return, what are you doing with the returned value? The second you go one level up, you have the result and promptly do nothing with it. You should return back up now that you have something meaningful. But why did cellID in the alert() return the expected value? IAmKale fucked around with this message at 22:44 on Dec 14, 2012 |
# ? Dec 14, 2012 22:40 |
|
No, you are returning the result of that function call up a level. The call is evaluated, then raturned up a level, which is the evaluation, so returned up a level, etc. etc. You could do: var temp = getLastSegment(objCellArray[cellID].next, false); return temp; And it would work too. Its just a waste of resources/ I just don't think that way. You aren't doing anything with the value that is returned and then the function completes without returning anything in your original code.
|
# ? Dec 14, 2012 22:43 |
|
Wozbo posted:You aren't doing anything with the value that is returned and then the function completes without returning anything in your original code. And sorry if I sound obtuse, I just want to make sure I understand the why moreso than just "remember to add return".
|
# ? Dec 14, 2012 22:50 |
|
No problemo. Recursion can be mighty confusing at times.
|
# ? Dec 14, 2012 23:03 |
|
Karthe posted:
Are you using your browser's Javascript debugger? Because if you are not, you should(*. Using alert like that is pretty 2002. * Depending on browser: In Chrome and Opera, right click somewhere on the page and select "inspect element" in Internet Explorer, press F12 in Firefox, you need to install Firebug, then right click anywhere and select Inspect element with Firebug You can set breakpoints and watches and such in the debugger and see what the values of any variables are without having to "alert" them.
|
# ? Dec 15, 2012 00:11 |
|
Wheany posted:Are you using your browser's Javascript debugger? Because if you are not, you should(*.
|
# ? Dec 15, 2012 00:58 |
|
Karthe posted:Yeah, you're right...those were just easier for me to work with. I'd never tried until now to use Chrome's advanced debugging tools under the Source tab, but now that I've discovered it and figured out how to load up a script for analysis, I'll end up using it more often. alert() is not easier to work with than console functions, though. Like if you want to output the value of x and y in this loop: JavaScript code:
And besides log(), console has info(), warn() and error(), which you can use to print out different kinds of messages. They show up in different color, so as soon as you see red in your console, you know there was some error somewhere.
|
# ? Dec 15, 2012 10:21 |
|
Yeah, just DON'T use alert. It is always a slower debug tool than the variety of modern options you now have. If you need to be able to stop and analyze you can use breakpoints in your browser or drop:code:
|
# ? Dec 15, 2012 11:40 |
|
I am a huge sucker for debugger;. Being able to check out the contents of your maps and stuff during runtime is priceless.
|
# ? Dec 15, 2012 17:26 |
|
pksage posted:I am a huge sucker for debugger;. Being able to check out the contents of your maps and stuff during runtime is priceless. Or you could just set a breakpoint in whatever debugging software you use. I don't quite see the point of adding an extra line of code, especially when it could cause a lot of issues if it ends up being left in.
|
# ? Dec 15, 2012 17:50 |
|
Blinkz0rz posted:Or you could just set a breakpoint in whatever debugging software you use. I don't quite see the point of adding an extra line of code, especially when it could cause a lot of issues if it ends up being left in. Or you could block any commits that contain "debugger;" and that way you still get the benefit. You are using version control, right?
|
# ? Dec 15, 2012 18:23 |
|
thelightguy posted:Or you could block any commits that contain "debugger;" and that way you still get the benefit. Yup, I have the ExtJS compiler leave out all debugger lines. For some reason, one of my source files keeps getting compressed down to one line in Chrome's debugger (before running any compressors on it), so I can't set a breakpoint without using debugger. I should probably figure out what's doing that instead of using debugger, but
|
# ? Dec 15, 2012 19:27 |
|
pksage posted:Yup, I have the ExtJS compiler leave out all debugger lines. For some reason, one of my source files keeps getting compressed down to one line in Chrome's debugger (before running any compressors on it), so I can't set a breakpoint without using debugger. I should probably figure out what's doing that instead of using debugger, but If you click the "pretty print" (curly braces) icon at the bottom of the Chrome debugger, it'll auto-format the code, which breaks it onto separate lines.
|
# ? Dec 15, 2012 20:06 |
|
Is is possible to add a clip region mid path, so that it only affects everything after the clip region is defined? And how does this interact with the nonzero winding rule? I'm getting some strange results and I'm wondering if there's any info on this. Google isn't helping me.
|
# ? Dec 16, 2012 21:58 |
|
I thought the clip region only applied at fill/stroke time. It's possible it's undefined. Report an issue to the WHATWG about it, and they'll clear up the specs.
|
# ? Dec 16, 2012 22:01 |
|
JSLint updated a few days ago to always give you poo poo if you use tabs instead of spaces. The commit message on GitHub just says "use_spaces". I like JSLint because I write all of my JavaScript in Notepad++ and then run it through to see how badly I messed up, but it keeps getting stricter and more opinionated.
|
# ? Dec 17, 2012 07:48 |
|
|
# ? Jun 8, 2024 07:26 |
|
I think my favorite is still "stupid". It used to complain to you if you had a function that contained "Sync" anywhere in its name (indexOf("Sync") > -1), but it was changed so that it only matches names ending in "Sync". But not before a coworker decided that instead of using the "stupid" option, he renamed a function named something like "checkSynchronizationComplete" to something else. Of course the option's documentation is "tolerate stupidity" instead of, let's say, "tolerate synchronous functions." Of course if the documentation said that, he might have to change the option to "synchronous" or something. e: Wait, so using tabs is not even an option? It just straight-up does not allow the tab character anywhere? Wheany fucked around with this message at 08:19 on Dec 17, 2012 |
# ? Dec 17, 2012 08:13 |