[javascript] How to check if anonymous object has a method?