javascript: implement something like python's __getattribute__? -
is there way implement in javascript functionality of python's __getattribute__() (or __getattr__())? is, method called whenever object called method name or property name cannot resolved?
for example, mechanism implement of following:
# python's method syntax o.name(args) # o.__getattr__('name') called , returns # function called args # alternative method syntax o.name(args) # o.__getattr__('name', args) called , returns value # properties syntax o.name = v # o.__getattr__('name', v) called v = o.name # o.__getattr__('name') called , returns value i'm interested in method syntax, property syntax nice bonus. thanks!
as pointed out @thg435 issue discussed in narrower scope @ is there equivalent of __nosuchmethod__ feature properties, or way implement in js? answer there applies here.
an appropriate api doing in javascript in making, called ecmascript harmony proxies may have been replaced direct proxy. api not yet supported cross-platform, may work platform, such recent firefox , chrome.
Comments
Post a Comment