PDA

View Full Version : do u have extra comma? ok, ie will destroy your application!



luke83
8 Nov 2006, 1:59 AM
i know there is no man stupid like me.. but u never can say :D

ok..

i was buliding my own application and thanks to jack.. very fastly i'm learning more about js..

so..

sometime i check the ie rendering.. 'cause u know.. not everyone is so cool to use ff :D

i opened my page and nothing appears

after calling every know peaple near bill gates, his family and used a my woodo doll vs him..

i notice a thing:



[..]
titlebar: true,
collapsible: true, <--- we usually split period with it.. now we can broke our applications.. :D
},


ff rocks, ie?

so if u have a problem and don't know why cancel a comma....:D

jack.slocum
8 Nov 2006, 5:14 AM
That's funny. If you do a search on "comma" in this forum I bet it's the most common problem.

luke83
8 Nov 2006, 6:42 AM
sorry.. if it is duplicate delete it :oops:

i only try to be useful to the community 8) :roll:

jack.slocum
8 Nov 2006, 5:28 PM
No it is very useful. I may sticky it. :)

christocracy
9 Nov 2006, 8:21 AM
need to raise the comma problem into everyone's consiousness,

zpao
9 Nov 2006, 8:43 AM
FYI: Opera has the same problem.

Question: Is this just IE6, or does it happen in 7 as well? (I haven't updated yet)

JeffHowden
9 Nov 2006, 12:04 PM
I format my lists with leading commas instead of trailing.


propsGrid.setSource({
"(name)": "Properties Grid"
, "grouping": false
, "autoFitColumns": true
, "productionQuality": false
, "created": new Date(Date.parse('10/15/2006'))
, "tested": false
, "version": .01
, "borderWidth": 1
});

christocracy
9 Nov 2006, 12:35 PM
for me, it's not really an issue of where I put commas,
it comes from removing a function from a class and forgetting the preceeding comma

before


var SomeClass.prototype = {
onInit : function() {

},

onLoad : function() {

}
}


Later, you might remove the last function (moving to a baseclass, for example) and you're left with:


var SomeClass.prototype = {
onInit : function() {

},

}

grimboy
9 Nov 2006, 3:19 PM
@christocracy: Which is exactly why leading commas are good. Where the cursor is # in vim (but deleting lines is deleting lines).



var SomeClass.prototype = {
onInit : function() {

}
#
, onLoad : function() {

}
}


<esc> 4dd



var SomeClass.prototype = {
onInit : function() {

}
#}


So yeah, use leading commas. They'll solve all of your problems

digerata
9 Nov 2006, 7:00 PM
They don't solve all of your problems...

What happens if you delete onInit() in your example?

DOH!

In reality, its a habbit you just have to learn. After every copy/cut/paste, check your commas.

gcsolaroli
10 Nov 2006, 2:34 AM
To ease the pain of comma checking, I have came up with this solution in the code I write:


var SomeClass.prototype = {
onInit : function() {

},

onLoad : function() {

},

__sintaxFix__: "sintax fix"
}



Appending the __sintaxFix__ dummy value at the end of every class definition, I have start saving all the mental energy of the "check comma" procedure. :-)

Animal
16 Nov 2006, 4:40 AM
Opera highlights this error on its Tools->Advanced->Error Console

Just change the Filter to Javascript, and you get to see syntax errors. Redundant commas in a property list are included.

jbowman
16 Nov 2006, 7:29 AM
To ease the pain of comma checking, I have came up with this solution in the code I write:


var SomeClass.prototype = {
onInit : function() {

},

onLoad : function() {

},

__sintaxFix__: "sintax fix"
}



Appending the __sintaxFix__ dummy value at the end of every class definition, I have start saving all the mental energy of the "check comma" procedure. :-)

Since we're already using so much bandwidth to shoot out the yui and yui-ext, that's just that much more bandwidth used for every object you create. I'm not sure that's an ideal situation for the environment we're working in?

gcsolaroli
17 Nov 2006, 1:40 PM
A JavaScript compressor (I use Dojo version of the custom modification of Rhino) added to serving the scripts compressed (with something like mod_gzip) can reduce the size of all the data to very reasonable dimensions.

If this is still not enough, you can alway write down a regular expression to tear the extra istructions off when building your package.

Every time you aim at saving computer resources at the cost of extra human effort, I think you are making the wrong choice. But YMMV.

jack.slocum
17 Nov 2006, 8:21 PM
IMO the best solution is make sure you don't include an extra comma. :)

jay@moduscreate.com
21 Nov 2006, 7:09 AM
exactly. It's considered poor programming to leave extra characters. I know the original poster feels that IE Sucks (which i feel the same way), but in many ways - it seems that the JS Engine is more restrictive and less forgiving than FF, which is actually Better!

Try to script using perl strict... it's better that way!

ismoore
27 May 2007, 4:48 AM
I have started using this

,\s*}
on a regular basis to test. Not sure if it will work in all RegExp editors but it is fine in Eclipse

Finds all line where a comma is followed by some optional whitespace and a close curly bracket.
Eclipse seems to consider whitespace to include newlines so you might need to modify the "\s" if that is a problem.

jsakalos
27 May 2007, 6:14 AM
There is an alternative here: Leading comma or Trailing comma: that is the question. (http://extjs.com/forum/showthread.php?t=6796&highlight=leading+comma)

Just my 2 cents... ;)

ismoore
27 May 2007, 11:02 AM
I have to agree that leading comma looks better. However, my problem was what to do with the thousands of lines of working code that fails on IE! that was a quicker way to get 'em all at once.
I use JSEclipse so maybe that is a good feature/enhancement to ask for that the bad comma's generate a syntax error (a preference of course :) ).

jsakalos
27 May 2007, 11:38 AM
I have to agree that leading comma looks better. However, my problem was what to do with the thousands of lines of working code that fails on IE! that was a quicker way to get 'em all at once.
I use JSEclipse so maybe that is a good feature/enhancement to ask for that the bad comma's generate a syntax error (a preference of course :) ).

I have no personal experiences but I've read here that Opera will show you where the extra commas are.

jack.slocum
27 May 2007, 11:48 AM
IntelliJ's JS editor detects them.

francescoNemesi
4 Jun 2007, 12:30 AM
Just wanted to say thanks for this life saving thread... especially Animal's tip on how to find extra commas with Opera.

The more I use ExtJs the greater it becomes.

Francesco

mchenryc
4 Jun 2007, 6:13 AM
I tend to agree with Jack, that trailing commas are easier to read.

To keep my trailing comma style from tripping me, I run <javascriptlint (http://www.javascriptlint.com)>, or <jslint (http://www.jslint.com)> before testing on IE, which of course comes before release. They often find other gotchas of the language (though can be a bit pedantic). Both can be run via simple, online form, but I prefer javascriptlint for it's error messages, and command line use.

jsakalos
4 Jun 2007, 5:01 PM
I tend to agree with Jack, that trailing commas are easier to read.

To keep my trailing comma style from tripping me, I run <javascriptlint (http://www.javascriptlint.com)>, or <jslint (http://www.jslint.com)> before testing on IE, which of course comes before release. They often find other gotchas of the language (though can be a bit pedantic). Both can be run via simple, online form, but I prefer javascriptlint for it's error messages, and command line use.

This is very useful advice. I've used web jslint on my code (I guess javascriptlint runs only on Windows) and it is really pedantic and found many "errors".

I recommend to use one of these tools to everybody.

Thanks.

Nabeel
29 Jun 2007, 3:48 AM
Hi, This post is very informative, however I would like some specific information. If someone can help me then please send me a private message. Best Regards,

tryanDLS
29 Jun 2007, 8:08 AM
Support is not conducted via private messaging. Post a specific question - start a new thread, don't use this one. If you feel that you need more immediate help than the public support forum provides, please see the this http://extjs.com/ext-store

marve
9 Jul 2007, 3:53 AM
when trying to figure out why the IE doesn't render my pages properly,
I usually start with running jsl (http://www.javascriptlint.com/) over my files instead of trying to figure out where the 'Object expected' might come from...
Having all more or less serious problems reported by jsl fixed, there will usually be no problems with IE after all.

Deleter
23 Jul 2007, 12:14 AM
Maybe I am wrong but JSLint can help you to check JS syntax! Visit it here http://www.jslint.com/

robertos
28 Jul 2007, 11:37 AM
just registered, and i saw this topic first an funny thing this comma thing just happened to me a few moments ago and i wanted to post:)

Luckily this was my SECOND time and i found it more quickly this time, it was the first thing i thought to check.

HINT: I checked buy manually removine all external <script src="...."></script>
from my source file. I hope it will help somebody because this is how i found the buggy file.:)

nowhere
30 Jul 2007, 12:04 AM
Try to use Aptana IDE, it'll help to debug the javascript code.

MaximGB
12 Aug 2007, 8:13 AM
Tip:
----
On windows one can use WSH cscript.exe to check for any syntax errors which IE don't like.
Just do cscript <your_file.js> and before a lot of runtime errors cscript will report you about syntax ones.

totl
14 Aug 2007, 1:50 AM
FYI: Opera has the same problem.

Question: Is this just IE6, or does it happen in 7 as well? (I haven't updated yet)
IE7 has the same problem. I ran into it a few times.

For Christ's sake, can't Microsoft just distribute good applications instead of crap!? (rhetorical question)

dearplato
4 Sep 2007, 10:48 PM
It's works.



<XML ID="JavaScriptCode" Memo="User's code goes here...">
<JavaScriptCode><![CDATA[
ary = [
{name: 'AAA', type: 'string'},
{name: 'BBB', type: 'string'},
{name: 'CCC', type: 'string'},
{name: 'DDD, type: 'string'},
{name: 'EEE', type: 'string'},
{name: 'FFF', type: 'string'},
{name: 'GGG', type: 'string'}
];
]]></JavaScriptCode>
</XML>

<script id="Ext.Generator" type="text/javascript" language="javascript">

if(JavaScriptCode.documentElement.text!=null)
{
try
{
eval(JavaScriptCode.documentElement.text);
//if no error occurs...
for(var i=0;i<ary.length;i++)
{
if(typeof(ary[i])!="object")
{
var err = new Error();
err.number="123";
err.name="User-defined field error";
err.message=String.format("Error occurs at no.{0} field",i);
throw err;
}
}
}
catch(e)
{
return Ext.MessageBox.alert("Syntax error",String.format("Code Segment:{0}<br/>Error Code:{1}<br/>Error Type:{2}<br/>Error Description:{3}","JavaScriptCode",e.number&0xFFFF,e.name,e.message));
}
}

</script>

ilia
8 Sep 2007, 7:26 AM
safari also doesn't like trailing commas

seade
16 Jan 2008, 7:20 PM
I'm using Ext 2.0, but this entire thread applies to 2.x anyway.

I had inadvertently included the following, note the bad closing tag:
<a>foo<a> rather than:
<a>foo</a> In Firefox the code with the bad closing tag worked everywhere. In IE (6 or 7) it worked in some places, but as soon as the bad content was used in a border layout IE threw up an error "Invalid source for this operation" with a stack trace deep into Ext. Locating the problem was quite a challenge (though validating the xhtml would of course have highlighted the problem immediately).

In case it is relevant, my doctype is:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
HTH,

Scott

seade
30 Jan 2008, 3:24 AM
Continuing my hijacking of this thread to cover serious traps that can take a while to figure out...

This is again Ext 2.0, but I am 99% sure it would impact Ext 1.x as well.

I have always declared scripts thus:


<script type="text/javascript">
<!--
// my script code here
//-->
</script>
The included HTML comment markers were included way back when the very early browser versions did not support the script tag - since these would be ignored the HTML comment would stop the script code from being displayed affected browsers. Of course now days the no such browsers exist and hence there is no benefit at all in including the HTML comment code - in fact it can really come back to haunt you.

If a page that includes a script declared with HTML comment markers is loaded via an AJAX call in IE (6 & 7) you will get a nasty looking error: "Erorr: Could not complete the operation due to error 80020101". There are threads (http://extjs.com/forum/showthread.php?t=15629) that mention this, but to summarize, when asked to execute the scripts in content loaded in this manner IE chokes on the HTML style comments (the "<!--" and "-->"). The solution is to just not include them thus:


<script type="text/javascript">
// my script code here
</script>
If you cannot modify the content you are loading there is a great way to remove it thanks to Animal (http://extjs.com/forum/showthread.php?p=76281#post76281):


Ext.Updater.BasicRenderer = function(){};
Ext.Updater.BasicRenderer.prototype = {
render : function(el, response, updateManager, callback){
el.update(response.responseText.replace("<!--", "").replace("-->", ""), updateManager.loadScripts, callback);
}
};
I hope this summary helps others.

Scott

sigaref
7 May 2008, 2:52 AM
For finding extra commas minify your code and look for ",]" or ",}", this way you can find some of them :)

jareddd
22 Jul 2008, 2:51 PM
We came across the same issue today with our code. Trailing comas caused a big fat error in IE7.

We found this blog entry and followed the steps to download and run the script debugging within visual studio. If you follow the instructions, you'll be able to track down where the comas are missing.

http://www.jonathanboutelle.com/mt/archives/2006/01/howto_debug_jav.html

This one worked for us.

ajmujaa
6 Aug 2008, 2:57 AM
Hello Buddy
I am using Netbeans for develop GWT Application,
I dont know how to add the chart, I mean when I run the program It asks the yui jar file
I added it also,
If u can pls tell me how would be the project structure for this thing when using Jsp Servlet with netbeans and how can i add the bar chart for the panel
Pls reply

Thanks
Mujahid

OverQualify
13 Aug 2008, 4:47 AM
I've written a little perl and bash script to remove trailing commas like {,} or [,].
Very simple scripts
They are available at
http://benediktlang.de/2008/08/05/trailing-comma-replacer-script-to-remove-extra-commas-from-javascript-files/

Use this without any warranty, for me it works.

k.j.prabu
17 Sep 2008, 12:36 AM
Thanks