Skip to content

Comment on Metaprogramming: Ruby vs. Javascriptparent

Comments

There is no metaprogramming going on in the JavaScript here.

Correct. The author compares Ruby to JavaScript in a situation which requires metaprogramming in Ruby, but not in JavaScript.

Metaprogramming inside of a running JS system would involve eval()

Incorrect. You could implement pre/post conditions in JavaScript by using metaprogramming, and it would not use eval(). The basic idea would be to iterate functions on MyClass.prototype, replacing each one with a new function that calls the original. This would be code (the pre/post implementation) modifying code (the MyClass definition).

Please read the article and think about its quality before voting.

Please calm down, the article is useful to Ruby people who are unfamiliar with JavaScript, and the literal definition of metaprogramming (code that modifies code) is largely misunderstood anyway. The most correctly you could ever use the term would be in reference to runtime or compile time optimization or safety checking, instrumented profiling, or logging, and I rarely ever see it used that way.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.