有没有办法在javascript中实现python的__getattribute__()(或__getattr__())的功能?也就是说,每当使用无法解析的方法名称或属性名称调用对象时调用的方法?
例如,实现以下任何一项的机制:
# Python's method syntax
o.Name(args) # o.__getattr__('Name') is called and returns
# a function which is called with args
# Alternative method syntax
o.Name(args) # o.__getattr__('Name', args) is called and returns a value
# Properties syntax
o.Name = v # o.__getattr__('Name', v) is called
v = o.Name # o.__getattr__('Name') is called and returns a value
我对方法语法最感兴趣,但属性语法将是一个不错的奖励。谢谢!