Determine if a JavaScript property has a getter or setter defined?

I think you're looking for getOwnPropertyDescriptor?


You can use Object.getOwnPropertyDescriptor(obj, prop)

For example:

var obj = { first: 1 }
obj.__defineGetter__('second', function() { return 2; });

// get descriptors
var descriptor1 = Object.getOwnPropertyDescriptor(obj, 'first');
var descriptor2 = Object.getOwnPropertyDescriptor(obj, 'second');

// check if it's a getter

descriptor2.get
// returns function () { return 2; }

descriptor1.get
// returns undefined