|
But the interpreter is going to add more ; anyway, it is not like you are going to convince it that you know your poo poo and it does not need to put a ; after return
|
# ? Jan 15, 2011 19:31 |
|
|
# ? May 21, 2024 01:10 |
|
Vanadium posted:But the interpreter is going to add more ; anyway, it is not like you are going to convince it that you know your poo poo and it does not need to put a ; after return OK Mr. Real Programing Tough Guy, I see the error of my ways! You should email everyone to make sure they know.
|
# ? Jan 15, 2011 19:39 |
|
Lua and Ruby the semi-colon is defined as optional. ECMAScript the semicolon is not-optional, but the interpreter tries to fix this for you, and is usually wrong.
|
# ? Jan 15, 2011 19:51 |
|
NotShadowStar posted:Lua and Ruby the semi-colon is defined as optional. ECMAScript the semicolon is not-optional, but the interpreter tries to fix this for you, and is usually wrong. Now way, you are just trying to impress people with those semi-colons dude. If you used real language, you'd know what a n00b you are. I bet you even indent your code... the interpreter just ignores that whitespace, so why bother putting it in!!!
|
# ? Jan 15, 2011 19:54 |
|
NotShadowStar posted:Lua and Ruby the semi-colon is defined as optional. ECMAScript the semicolon is not-optional, but the interpreter tries to fix this for you, and is usually wrong. ECMA-262 posted:7.9 Automatic Semicolon Insertion
|
# ? Jan 15, 2011 20:26 |
|
7.9 should get some sort of special award for most-unlike-RFC2119 use of 'must' and 'may' in a computer-related spec:quote:Certain ECMAScript statements (empty statement, variable statement, expression statement, do-while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. More substantially, however, semicolon insertion is really worst of both worlds: some of the time it happens as parse error recovery, and some of the time the interpreter is required to infer a semi-colon in a way that just emulates a combination of enforcing a bizarre restriction on whitespace with parse error recovery.
|
# ? Jan 15, 2011 20:47 |
|
Try using a JavaScript minifier and concatenator with missing semi-colons. Some, like YUI Compressor, fare better than others because they run the code through an actual JavaScript interpreter so they can insert semi-colons where necessary when compressing the code, but others like jsmin just try and remove whitespace which can really blow things up when line returns are removed. The optional use of semi-colons in ECMAScript was kind of a bad decision because of network concerns I guess. Ruby and Lua aren't really meant to be served out across networks where minification can help reduce file size and get things to the user quicker, but in JavaScript this is a concern, so treating semi-colons as optional is not a good idea. Just pretend that that part of the spec doesn't exist and use semi-colons religiously, and dammit use jslint and other JavaScript linters. They will make you produce better code, period.
|
# ? Jan 15, 2011 20:51 |
|
There Will Be Penalty posted:code:
|
# ? Jan 15, 2011 21:24 |
|
Where in that example would putting an explicit semicolon fix anything
|
# ? Jan 15, 2011 21:42 |
|
It doesn't fix anything, automatic insertion of semicolons break the statement completely and forces you into a coding style. Here's how it looks after semicolon insertion code:
code:
|
# ? Jan 15, 2011 21:46 |
|
Ruby forces you to do ary.each do { derp } and does not allow ary.each do { derp } either
|
# ? Jan 15, 2011 22:14 |
|
Vanadium posted:Ruby forces you to do ary.each do { derp } and does not allow ary.each do You can't do both the "do" statement and curly braces together for blocks in Ruby, it has to be one or the other. What you have there is a syntax error.
|
# ? Jan 15, 2011 23:54 |
|
dark_panda posted:You can't do both the "do" statement and curly braces together for blocks in Ruby, it has to be one or the other. What you have there is a syntax error. Give him a break, he's trying to pick a e-fight with us "lesser" programmers; facts are irrelevant. (Hmm, I wonder if that semicolon in my sentence was superfluous.)
|
# ? Jan 16, 2011 00:00 |
|
If you have to ask, it already is.
|
# ? Jan 16, 2011 00:23 |
|
dark_panda posted:You can't do both the "do" statement and curly braces together for blocks in Ruby, it has to be one or the other. What you have there is a syntax error. Fine, remove the do
|
# ? Jan 16, 2011 02:36 |
|
Vanadium posted:Fine, remove the do So what exactly was your javascript question?
|
# ? Jan 16, 2011 04:02 |
|
Vanadium posted:Ruby forces you to do ary.each do { derp } and does not allow ary.each do Because that's ambiguous. The Ruby VM does not and will not ever try and figure out what you intended. It's the same as optional parentheses in Ruby until it becomes ambiguous. For example code:
code:
So what about 'do' then? The problem comes from newlines are taken as statement terminators in Ruby unless explicitly escaped with \. When you terminate a statement like [1, 2, 3].each(), each is actually returning an Iterator that is normally handled by the block. code:
code:
code:
tl;dr Ruby is a much smarter design because it never attempts to guess what you do, the automatic semicolon insertion is bad because it attempts to be smart at what you're doing and will fail.
|
# ? Jan 16, 2011 04:22 |
|
Both ruby and js put ; at the end of every line unless there is like a , there or an open ( somewhere or whatever! Why is it a big deal for one of them and not the other?
|
# ? Jan 16, 2011 04:42 |
|
It will not be invoked after an infix operator at EOL. It will also not be invoked if your innermost matching brackets are parenthesis, square brackets, or curly brackets used for object literal notation. I use these as rules of thumb about where it's safe to insert a newline (because gently caress a bunch of lines that are more than 80 columns long). So there's no reason to worry about any of the following statements: code:
code:
There Will Be Penalty fucked around with this message at 06:43 on Jan 16, 2011 |
# ? Jan 16, 2011 06:04 |
|
Vanadium posted:Both ruby and js put ; at the end of every line unless there is like a , there or an open ( somewhere or whatever! You're just posting poo poo and not even reading. Ruby does not put a semicolon at the end of a line. Ruby has two ways of terminating a statement, semicolon character and end of line character (technically two of them for UNIX and DOS EOL characters). puts "something" and puts "something"; are NOT exactly the same. In the first one the parser tree it looks something like (drastically simplified) statement_begin method_call(arguments) end_statement The second one reads statement_begin method_call(arguments) end_statement statement_begin end_statement If you actually read instead of vomiting bullshit, you'd be astute enough to note that you can break lines with Ruby using \ If you were even more astute, you'd realize that \ is special... hm... Oh! Knowing that the end of line characters (\n, \r\n) are statement terminators, and the \ character is an escape character... you're escaping the statement terminator! tl;dr again everything you have posted has been quite factually wrong. tl;dr v2 Shut up kid, men are talking. NotShadowStar fucked around with this message at 06:22 on Jan 16, 2011 |
# ? Jan 16, 2011 06:18 |
|
There Will Be Penalty posted:I believe it's safe to say that automatic semicolon insertion is invoked when it *can* be, i.e., when it won't cause a syntax error to do so at EOL. Why speculate? See ECMA-262-5, 7.9, as was cited before for exact spec. And you're pretty much backwards --- it's only invoked when the program would not parse otherwise (with the bizarro provision that some statements and expressions don't permit a line break before/after their arguments) <snip> There Will Be Penalty posted:] = 5;[/code]It *will* be invoked if your innermost matching brackets are the curly brackets surrounding the body of a function, of course: Nope, it's not. x is 11.
|
# ? Jan 16, 2011 06:22 |
|
well gently caress if the parser tree says so (USER WAS PUT ON PROBATION FOR THIS POST)
|
# ? Jan 16, 2011 06:31 |
|
Vanadium posted:well gently caress if the parser tree says so Could you just stop making GBS threads up the thread please? I'm sorry you don't like yourself and feel the need to put down us poor saps who use javascript and add semicolons where we technically don't need them so you can look in the mirror and see a big man, but since you've done nothing but show how ignorant you are, you might want to find somewhere else to troll.
|
# ? Jan 16, 2011 07:09 |
|
So here's a dumb question: I am trying to use Google's Blobstore (http://code.google.com/appengine/docs/python/blobstore/overview.html). In order to upload data, they require you post to a serving URL that you embed in the client's JavaScript (yay, got that) and that the data come from a form with an input type="file" element. Now, what I really want to send is some data I have in a JavaScript string variable. Is it possible for me to POST (with enctype="multipart/form-data") that data somehow? Basic Googling seems to indicate this is not really possible with any of JQuery's AJAXy functions, but that Dojo might have some promise (http://dojotoolkit.org/reference-guide/dojo/io/iframe.html#dojo-io-iframe). However, I can't really see how to put the string data I have into a generated input="file" form. Is this just not possible? If so, why is this stuff not possible?
|
# ? Jan 16, 2011 11:02 |
|
Vanadium posted:well gently caress if the parser tree says so I'm starting to see why the Minecraft threads always have deadly titles if these are the people that come from them.
|
# ? Jan 16, 2011 15:06 |
|
Evil Robot posted:So here's a dumb question: With jQuery, the following should allow you to set the right header: code:
|
# ? Jan 16, 2011 15:36 |
|
File upload can't be done through Ajax alone, you need to use an iframe or Flash to make it look like it's something Ajaxy.
|
# ? Jan 16, 2011 18:12 |
|
Parantumaton posted:File upload can't be done through Ajax alone, you need to use an iframe or Flash to make it look like it's something Ajaxy. Yeah this is the problem.
|
# ? Jan 16, 2011 22:35 |
|
Lumpy posted:
snapshotLength is the number of items in the snapshot returned by the document.evaluate call that's doing an XPath query on the current DOM. I don't know for sure why they don't stuff them into a regular array, but I'd guess they wanted to make it extra clear that you can't just add more nodes into the result of evaluate and expect them to show up in the DOM. https://developer.mozilla.org/en/XPathResult It's pretty neat because you can use it like jQuery's selectors* when you write a user script for browsers that aren't total garbage. *Actually, I read that jQuery's selector engine just uses XPath queries on browsers that support them, but have been to lazy to verify
|
# ? Jan 17, 2011 17:07 |
|
Pretty sure the XPath selector backend was removed from jQuery, since the browsers who supported it all support document.querySelectorAll now anyway. And since we're on the subject of jQuery: code:
|
# ? Jan 17, 2011 17:54 |
|
Nigglypuff posted:Pretty sure the XPath selector backend was removed from jQuery, since the browsers who supported it all support document.querySelectorAll now anyway. Look at all those useless semicolons. Serious question: why the use of new function() and arguments.callee instead of a local var that's assigned the function and then a reference to that in the timeout? I know what you are doing is effectively equivalent, but interested if there is an advantage to doing it your way.
|
# ? Jan 17, 2011 19:06 |
|
Nigglypuff posted:Pretty sure the XPath selector backend was removed from jQuery, since the browsers who supported it all support document.querySelectorAll now anyway. That doesn't work in the latest Firefox 4, for what it's worth. Same problem with only opening the first thread as the original code had.
|
# ? Jan 17, 2011 19:35 |
|
Lumpy posted:Look at all those useless semicolons. And all that whitespace Lumpy posted:Serious question: why the use of new function() and arguments.callee instead of a local var that's assigned the function and then a reference to that in the timeout? I know what you are doing is effectively equivalent, but interested if there is an advantage to doing it your way. You're just pretending not to know something in an attempt to fit in with the rest of us.
|
# ? Jan 17, 2011 19:35 |
|
What the hell does "new function (){...};" even do? Don't you have to actually call the function like so: "new (function() {...})();" ?
|
# ? Jan 17, 2011 19:45 |
|
peepsalot posted:What the hell does "new function (){...};" even do? Don't you have to actually call the function like so: "new (function() {...})();" ? It calls the anonymous function/function expression as a constructor --- so 'this' is set to a fresh object inside the function (since the function object doesn't have .prototype), and the entire expression evaluates to that object. So basically the same as: var tmp = function () { .... } new tmp; ... just without storing it. Edit: change example to be closer.
|
# ? Jan 17, 2011 20:37 |
|
epswing posted:You're just pretending not to know something in an attempt to fit in with the rest of us. Most folks don't know to do crazy stuff like that, so explaining it would probably be helpful to most.
|
# ? Jan 17, 2011 21:02 |
|
OddObserver posted:It calls the anonymous function/function expression as a constructor --- so 'this' is set to a fresh object inside the function (since the function object doesn't have .prototype), and the entire expression evaluates to that object.
|
# ? Jan 17, 2011 21:06 |
|
I'm writing a script that finds a phrase in a page and then determines if the previous link matches one in an array of objects, and if it doesn't adds that link to the end of that array. For some reason it isn't working, however. It finds the phrase but doesn't collect the link. Can anyone see what's going wrong?code:
|
# ? Jan 17, 2011 21:57 |
|
Insurrectum posted:I'm writing a script that finds a phrase in a page and then determines if the previous link matches one in an array of objects, and if it doesn't adds that link to the end of that array. For some reason it isn't working, however. It finds the phrase but doesn't collect the link. Can anyone see what's going wrong? Don't use new Array() It makes baby jeebus cry. You will also trying to access the -1 element of bElms the first time through your loop, so that might be the cause of some woes. EDIT: use varName = [] instead. Lumpy fucked around with this message at 22:15 on Jan 17, 2011 |
# ? Jan 17, 2011 22:08 |
|
|
# ? May 21, 2024 01:10 |
|
Lumpy posted:Don't use new Array() It makes baby jeebus cry. You will also trying to access the -1 element of bElms the first time through your loop, so that might be the cause of some woes. I changed the array, but there's no way I'm going to be accessing bElems[-1], since I know the first instance of a link I'm looking for always occurs well into the document. (the first if condition makes sure of that)
|
# ? Jan 17, 2011 22:21 |