I am using the JQuery json plugin and trying to convert a custom object to JSON using the toJSON function. Here is the object:
function Customer(firstName, lastName, age) {
Customer.prototype.firstName = firstName;
Customer.prototype.lastName = lastName;
Customer.prototype.age = age;
}
And here is the $.toJSON applied:
var customer = new Customer('mohammad', 'azam', 28);
var a = $.toJSON(customer);
For some reason "a" is always empty.
But if I use the following code:
var params = new Object(); params.firstName = 'Mohammad'; params.lastName = 'Azam'; params.age = 28;
var a = $.toJSON(params);
then it works fine!
What am I missing when trying to perform toJSON on a custom object.