Archive for the ‘Quick Reference’ Category

Maintaining Context in a JavaScript Callback

For reference. To maintain context in a JavaScript callback use a closure and an anonymous function. For example: var curObj = this; //closure to get context in callback $(‘#foobar’).animate({ height: 100 }, 1000, "jswing", function() { alert(curObj.someProperty); }); To avoid the anonymous function use the Microsoft Ajax helper Function.createDelegate as follows: this.animate = function() { [...]

C# – Iterating through an Enum

Today I came across a situation where iterating through an Enum would save me about 10 lines of code and some time. The quickest way is as follows: foreach (MyEnum value in Enum.GetValues(typeof(MyEnum))) { //… }