tags:

views:

2124

answers:

4

I'm getting a "Object doesn't support this property or method error", does anyone know why?

I do have values plugged into userId, fname, lname, oname, sam, hasAccess

function Employee(id, fname, lname, oname, sam, access) {
    this.id = id;
    this.fname = fname;
    this.lname = lname;
    this.oname = oname
    this.sam = sam;
    this.access = access;
}

var emp = new Employee(userId, fname, lname, oname, sam, hasAccess);

var jsonstuff = emp.toSource(); //Breaking here

Although this link says its possible http://www.w3schools.com/jsref/jsref_toSource_string.asp

Thanks everyone.

+4  A: 

Try using a JSON serializer instead. toSource is Mozilla specific and not supported by IE.

If you are just debugging then your best bet is going to be to install Firebug and use console.dir(emp); to print the contents of an object to the console window.

Update: Just notice that on the link you posted it says, "Note: This method does not work in Internet Explorer!" And on the MDC page is says "Non-Standard".

Prestaul
Oops! sorry guys didnt see that
Vince
+1  A: 

You can either call toString instead, or put in a condition like this...

var jsonstuff = (emp.toSource) ? emp.toSource() : emp.toString();

EDIT:

Since this is not working for you, you might want to use JSON.stringify()

Josh Stodola
+5  A: 

toSource() does not work in Internet Explorer or Safari. It is Gecko-only. See http://stackoverflow.com/questions/171407/implementing-mozillas-tosource-method-in-internet-explorer for alternatives.

John Kugelman
+1 for mentioning Safari! The browser world isn't just Firefox and IE.
Steve Harrison
Why the downvote?
John Kugelman
I didn't see mentioning Safari as point worthy.
Vince
@Vince: If your boss is that incompetent, try to explain to him that making sure that it works outside IE and FF will result in less maintenance work next time IE is upgraded. It will also make the IE and FF users much less annoyed with your company when they browse the site from their cell phone (no matter if it is an iPhone, a Nokia or something else without IE).
Fredrik
Don't forget Chrome is really getting into the fight. Leaving Safari+Chrome+Opera aside, you could be leaving 15% of the share (depending on your website market). Like an example, see: http://www.w3schools.com/browsers/browsers_stats.asp
lepe
@Vince: 1998 called, it wants its rhetoric back. Safari and Chrome share the Webkit rendering engine; together, it's a considerable share of the market. Also, if it works in FF, it's 90% chance it'll work in Safari,Chrome,Opera,etc. (not in IE though, that's more like a 50% chance)
Piskvor