how to tell if a javascript variable is a function

Use the typeof operator: if (typeof model[property] == ‘function’) … Also, note that you should be sure that the properties you are iterating are part of this object, and not inherited as a public property on the prototype of some other object up the inheritance chain: for (var property in model){ if (!model.hasOwnProperty(property)) continue; … … Read more

get methodinfo from a method reference C#

Slight adaptation of a previously posted answer, but this blog post seems to achieve what you’re asking for; http://blog.functionalfun.net/2009/10/getting-methodinfo-of-generic-method.html Sample usage would be as follows; var methodInfo = SymbolExtensions.GetMethodInfo(() => Program.Main()); Original answer was to this question; https://stackoverflow.com/a/9132588/5827

Difference between decltype and typeof?

There is no typeof operator in c++. While it is true that such a functionality has been offered by most compilers for quite some time, it has always been a compiler specific language extension. Therefore comparing the behaviour of the two in general doesn’t make sense, since the behaviour of typeof (if it even exists) … Read more

C# Reflection: How to get the type of a Nullable?

I’ve been using the following type of code to check if the type is nullable and to get the actual type: if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>)) { return Nullable.GetUnderlyingType(type); } If the type is e.g. Nullable this code returns the int part (underlying type). If you just need to convert object into specific type … Read more

Difference between nameof and typeof

Two reasons: nameof turns into a compile-time constant. typeof(…).Name requires a bit of reflection. It’s not overly expensive, but it can hurt in some cases. Second, it’s used for other things than type names. For example, arguments: void SomeMethod(int myArgument) { Debug.WriteLine(nameof(myArgument)); } You can also get the name of class members and even locals. … Read more

What’s the point of new String(“x”) in JavaScript?

There’s very little practical use for String objects as created by new String(“foo”). The only advantage a String object has over a primitive string value is that as an object it can store properties: var str = “foo”; str.prop = “bar”; alert(str.prop); // undefined var str = new String(“foo”); str.prop = “bar”; alert(str.prop); // “bar” … Read more