Skip to content Skip to sidebar Skip to footer

Different Javascript Object Literal Behaviour In Firefox & Google Chrome?

I have narrowed down my error to following set of codes producing different behaviour in google Chrome: Sample Code: http://jnvxxx.appspot.com/rpc/static_server?key_=testjs.html Fi

Solution 1:

You are accessing the window.status property, which is used to control the text in the status bar. See: http://www.w3schools.com/jsref/prop_win_status.asp.

Apparently, this functionality has to be turned on first in all major browsers, so apparently different browsers do different things when it's turned off. Chrome changes the value of the status property to a string, so it becomes the cryptic-but-familiar string "[object Object]", which has no entry_count property. Firefox leaves the object intact in the status property.

Bottom line: window.status is already being used for something else; use a different name for your variable.

EDIT:

As mentioned below, an even better way do do all this would be to encapsulate it in function scope, as long as you're not going to use it in other places anyway:

(function() {
   var myStatus = {...};
   // Do something with myStatus, preferably not document.write ;)
}());

var a = typeof myStatus; // a === 'undefined'.

This way, the variable will only be visible within the function scope.

Post a Comment for "Different Javascript Object Literal Behaviour In Firefox & Google Chrome?"