Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It doesn't need to be a class; that's a detail:

  function foo() { ... }
  var callthis = "foo"
  window[callthis]()
And this is true for any object; attaching functions to objects is kinda common.

And of course, "callthis" is usually defined in a much more complex way, such as if (user_input_is_this) callthis = "foo" else callthis = "bar". Or what about callthis = "foo"; callthis += "_bar"?

In general this kind of stuff is tricky in dynamic languages (and also in static languages once you start using reflection); JavaScript isn't really an exception here. You really need to have a deep understanding of the code and logic to truly be certain that something will never be called.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: