17 javascript
我得到一个"对象不支持此属性或方法错误",有谁知道为什么?
我确实将值插入到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
Run Code Online (Sandbox Code Playgroud)
虽然这个链接说它可能是http://www.w3schools.com/jsref/jsref_toSource_date.asp
Joh*_*ica 22
toSource()
在Internet Explorer或Safari中不起作用.它只是Gecko.请参阅在Internet Explorer中实现Mozilla的toSource()方法以获取替代方法.
你可以改为调用toString,或者放入这样的条件......
var jsonstuff = (emp.toSource) ? emp.toSource() : emp.toString();
Run Code Online (Sandbox Code Playgroud)
编辑:
由于这不适合您,您可能希望使用JSON.stringify()