Are there legitimate uses for JavaScript’s “with” statement?

Another use occurred to me today, so I searched the web excitedly and found an existing mention of it: Defining Variables inside Block Scope. Background JavaScript, in spite of its superficial resemblance to C and C++, does not scope variables to the block they are defined in: var name = “Joe”; if ( true ) … Read more

JavaScript hashmap equivalent

Hash your objects yourself manually, and use the resulting strings as keys for a regular JavaScript dictionary. After all, you are in the best position to know what makes your objects unique. That’s what I do. Example: var key = function(obj){ // Some unique object-dependent key return obj.totallyUniqueEmployeeIdKey; // Just an example }; var dict … Read more

Expression Versus Statement

Expression: Something which evaluates to a value. Example: 1+2/x Statement: A line of code which does something. Example: GOTO 100 In the earliest general-purpose programming languages, like FORTRAN, the distinction was crystal-clear. In FORTRAN, a statement was one unit of execution, a thing that you did. The only reason it wasn’t called a “line” was … Read more

What is the python “with” statement designed for?

I believe this has already been answered by other users before me, so I only add it for the sake of completeness: the with statement simplifies exception handling by encapsulating common preparation and cleanup tasks in so-called context managers. More details can be found in PEP 343. For instance, the open statement is a context … Read more

How to loop through all enum values in C#? [duplicate]

Yes you can use the ‍GetValue‍‍‍s method: var values = Enum.GetValues(typeof(Foos)); Or the typed version: var values = Enum.GetValues(typeof(Foos)).Cast<Foos>(); I long ago added a helper function to my private library for just such an occasion: public static class EnumUtil { public static IEnumerable<T> GetValues<T>() { return Enum.GetValues(typeof(T)).Cast<T>(); } } Usage: var values = EnumUtil.GetValues<Foos>();

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)