问题
Does JavaScript have the equivalent of Python's __getattribute__
? In the sense that I'd like an object, a
, for which a reference to a property x
is equivalent to a.__get__('x')
. Trying to get this to work in V8. Possible?
Example: an object which makes REST-ful calls:
RESTful("some-url").foo({x:1}) => response of call to "some-url/foo?x=1"
回答1:
It is not possible for properties, though there is a non-standard way (__noSuchMethod__) for methods which is only available for Firefox.
来源:https://stackoverflow.com/questions/3690394/does-javascript-have-the-equivalent-of-pythons-getattribute