I'm using the following function to retrieve all the properties of an object:
The only difficulty is that later when I try to set some of those properties I get the error: "setting a property that has only a getter."
Now I realize that I probably shouldn't be setting that property then (and don't ask WHICH property - it really doesn't matter, this is going to be dynamic, so lets say its ALL the returned properties).
How can I modify the function above to return only those properties that are "setters" - or how can I easily tell if a property is a "setter"?
Thanks.
Code:
function getProperties(obj) {
var i, v;
var count = 0;
var props = [];
if (typeof(obj) === 'object') {
for (i in obj) {
try{
v = obj[i];
if (v !== undefined && typeof(v) !== 'function' && typeof(v) !== 'object') {
props[count] = i;
count++;
}
}catch(err){}
}
}
return props;
}
The only difficulty is that later when I try to set some of those properties I get the error: "setting a property that has only a getter."
Now I realize that I probably shouldn't be setting that property then (and don't ask WHICH property - it really doesn't matter, this is going to be dynamic, so lets say its ALL the returned properties).
How can I modify the function above to return only those properties that are "setters" - or how can I easily tell if a property is a "setter"?
Thanks.