Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
can you tell me what is the javaascript comminted lines do?
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
// if (!o[this.name].push) {
// o[this.name] = [o[this.name]];
// }
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
1 Answer
- SilentLv 78 years agoFavorite Answer
The commented lines check to see if o[this.name] is an array (by checking the presence of the "push" function). If it's not an array, it replaces it with an array containing whatever it is.
This is not a great way of determining whether something's an array (since it gives a false positive on ANY object that has a property called "push"). Some better ways to do this can be found at the link below.