When is using __call__ a good idea?

I think your intuition is about right. Historically, callable objects (or what I’ve sometimes heard called “functors”) have been used in the OO world to simulate closures. In C++ they’re frequently indispensable. However, __call__ has quite a bit of competition in the Python world: A regular named method, whose behavior can sometimes be a lot … Read more

How to inherit static methods from base class in JavaScript?

In the classical (OO) inheritance pattern, the static methods do not actually get inherited down. Therefore if you have a static method, why not just call: SuperClass.static_method() whenever you need it, no need for JavaScript to keep extra references or copies of the same method. You can also read this JavaScript Override Patterns to get … Read more

Pass additional parameters to jQuery each() callback

You should be able to create a reference to your survey before you iterate over the questions. function Survey() { this.questions = new Array(); var survey = this; $(‘.question’).each(function(i) { survey.questions.push(new Question(this)); }); } function Question(element) { this.element = $(element); } var survey = new Survey(); $.each(survey.questions, function() { $(“ul”).append(“<li>” + this.element.text() + “</li>”); }); … Read more

Is method hiding ever a good idea

There are rare, but very good, reasons to use method hiding. Eric Lippert posted a great example on his blog: interface IEnumerable<T> : IEnumerable { new IEnumerator<T> GetEnumerator(); } However, I think hiding should be the exception, and only used sparingly.