Really really silly question, but I can't get this to work:
http://jsfiddle.net/t4R46/
function showOne(parentid, childid){
alert(parentid);
alert(childid);
}
<a href="#" onClick=showOne('div1', 'div2')>91</a>
Basically I want two parameters to be passed to the function but I get:
"Uncaught SyntaxError: Unexpected token }"
Is there any smart site to verify javascripts in? The error reporting in ie Chrome leaves a bit to be desired.
/Patrik
You need quotes around the attribute value:
91
<!-- here -----^ and here -----------^ -->
In HTML, an attribute value can only not have quotes if it doesn't have spaces (or a few other characters) in it. Since the value you want to set has a space in it, you need to put it in quotes.
Is there any smart site to verify javascripts in? The error reporting in ie Chrome leaves a bit to be desired.
You're looking for "lint" tools. Probably the most famous lint tool for JavaScript is Crockford's jslint. But it is heavily influenced by his personal style and opinions, so there's an active fork called jshint that's very popular. There are online and command-line versions of both. Some IDEs offer lint options as well, such as WebStorm from JetBrains.
Double quotes will help.
91
The best tools are : jshint, and jslint
You are missin "
91
FIDDLE
Related
edit: I didn't make it clear. I'm using play framework.
I have compilation error as follows:
"Parse error. IE8 (and below) will parse trailing commas in array and object literals incorrectly. If you are targeting newer versions of JS, set the appropriate language_in option."
But I can't find such an option to change language options. How can I get rid of this compilation error?
I can't modify js file - it is generated and is huge. Also, I really don't care about IE8 and below.
It would be great if someone could help me.
I always have noticed this, including in versions before as well. About half way through jQuery's compressed version you'll see some regex:
[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^
The error appears to be at ['"]
I'm sure it's not really a syntax error, but all my code editors recognize it as one, which makes development a pain if I try to combine JavaScript files. Does anyone know what's going on here?
It's a character entity in a regular expression, as specified by the square brackets. There are no restrictions on quote characters in them. All that's going on is buggy syntax highlighting. Ask the developer of your editor.
your code editor sucks, this isnt a syntax error if its inside of a regex literal, which i suspect it is.
the code editor you use probably doesnt support regex literals properly, and that its a string , which would cause the error
I know that some people consider the presence of a leading underscore to imply that a variable is "private," that such privacy is a fiction, and assume this is why JSLint reports such names with an error message.
I use Google Analytics on a Web site I am building. I make reference to GA's variables, such as "_gaq."
I am trying to get my JS code to be 100% JSLint clean (I'm not religious about my coding style, and so will go with Mr. Crockford's counsel). That said, I can't do anything about Google's variables names... so, I guess I can't get 100% "clean."
I post here in case I've misunderstood the message, and can do something to comply with JSLint practices.
Ah, I've got this handled... I wrap the statements that use the underscore prefixed variables with JSLint commands to disable, then re-enable this class of error:
/*jslint nomen: true*/
... statement(s) with _var ...
/*jslint nomen: false*/
The best way to handle this is just to enable the "Tolerate dangling _ in identifiers" (nomen) option. See http://www.jslint.com/lint.html for details...
JSLint is just a code quality tool. Not completely passing its tests does not mean your code is bad; it simply means you don't follow all the conventions laid out by its creator. Although JSLint makes very good suggestions, it is not always possible to fulfill them all, especially when using someone else's library which was not tested against it. Rather than littering your source code with meaningless meta-comments, you should check your code with the "Disallow dangling _ in identifiers" option disabled, since it seems not to makes sense to use with your particular code.
I use JSLInt with node.js. You can pass --nomen flag to get around this feature
jslint --nomen myfile.js
I have a lot of Expected '{' and instead saw 'blah' errors that spit out when I run my scripts through jslint. Is there an option that ignores this error?
There are no options to ignore this unless you edit the source of jslint and remove this particular warning. However, it is highly recommended not to ignore this rule.
no. crocky is a curmudgeon js nazi.;-) there is a vs addin on codeplex that i added an ignore feature to though. the addin is still kinda buggy but works well enough. I haven't been able to get contact with the owner to get on the project so havent put a lot more time into it. anyway see here and get the patch from the patches tab
Actually, with the latest version of sublime-jslint, I just told it to ignore these errors by adding to the "ignore_errors" option:
"ignore_errors":
[
"Expected '{' and instead saw"
],
Now whenever I run sublime-jslint on my files, I get:
jslint: ignored 5 errors.
Which javascript major modes exist in Emacs, and what are their key-features ?
js2-mode: a new JavaScript mode for Emacs This is part of a larger
project, in progress, to permit writing Emacs extensions in JavaScript
instead of Emacs-Lisp.
Features: M-x customize Accurate syntax
highlighting Indentation Code folding
Comment and string filling Syntax errors Strict
warnings jsdoc highlighting
http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
With some documentation.
I think what you want is this:
http://www.corybennett.org/download/javascript-mode.el
Then again, maybe this what you are looking for?
or this?
People seem to prefer (at least given the highest rated answer):
Updated: http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
I use Steve Yegge's js2-mode, and like it a lot. It's quite configurable, its indentation ideas match mine, and most impressively it has a full JavaScript parser in it, so it can alert me to syntax errors as I type (indispensable for little things like trailing commas in property lists that bork IE).
Espresso mode is supposed to be quite good as well.