1

Is there any function in javascript to do the same as the php function __call?

I wish I could do something like:

var obj = {
  __call: function(prop){
    console.log('Call obj.'+prop);
    return "fakeValue";
  }
}

obj.somePropertie // fakeValue

Obviously the goal is to not only log, but this is the idea

Falci
  • 1,823
  • 4
  • 29
  • 54
  • JavaScript has [getters and setters](http://ejohn.org/blog/javascript-getters-and-setters/) which offer a similar sort of syntactic sugar, but they're not what most people would consider "production ready". You're unlikely to encounter wide-spread support for them. – user229044 May 29 '14 at 20:36
  • Look up the `Proxy` object. A fun API to toy with, but not production-ready. – Rob W May 29 '14 at 20:36
  • no, ES6 might add stuff, but there is no method_missing in JS – dandavis May 29 '14 at 20:37
  • You can give a look at this: http://jsfiddle.net/RTThP/ – clami219 May 30 '14 at 10:17

0 Answers0