var test={   dha1:'Boolean',   dha2:'Boolean',   dha3:'Number',   dha4:'String' }  for(x in test){   console.log(test.x); }   Here i want my output as  Boolean Boolean Number String  But its return undefined for all four properties
31492
How do I enumerate the properties of a JavaScript object?  I actually want to list all the defined variables and their values, but I've learned that defining a variable actually creates a property of the window object.
45659
After an AJAX request, sometimes my application may return an empty object, like:  var a = {};   How can I check whether that's the case?
24310
I'm trying to get:  document.createElement('div')  //=&gt; true {tagName: 'foobar something'}  //=&gt; false   In my own scripts, I used to just use this since I never needed tagName as a property:  if (!object.tagName) throw ...;   So for the second object, I came up with the following as a quick solution -- which mostly works. ;)  The problem is, it depends on browsers enforcing read-only properties, which not all do.  function isDOM(obj) {   var tag = obj.tagName;   try {     obj.tagName = '';  // Read-only for DOM, should throw exception     obj.tagName = tag; // Restore for normal objects     return false;   } catch (e) {     return true;   } }   Is there a good substitute?
122201
You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C.  myObject.property = YES;   or  [myObject setProperty:YES];   Is there a difference in performance (in terms of accessing the property)? Is it just a matter of preference in terms of coding style?
2818
I know in JavaScript, objects double as hashes, but I have been unable to find a built-in function to get the keys: var h = {a:'b', c:'d'};  I want something like var k = h.keys() ; // k = ['a', 'c'];  It is simple to write a function myself to iterate over the items and add the keys to an array that I return, but is there a standard cleaner way to do that? I keep feeling it must be a simple built in function that I missed but I can't find it!
4059
The situation is somewhat like-  var someVar = some_other_function(); someObj.addEventListener("click", function(){     some_function(someVar); }, false);   The problem is that the value of someVar is not visible inside the listener function of the addEventListener, where it is probably being treated as a new variable.
119860
A weird bug was occurring in production which I was asked to look into. The issue was tracked down to a couple of variables being declared within a For loop and not being initialized on each iteration. An assumption had been made that due to the scope of their declaration they would be &quot;reset&quot; on each iteration. Could someone explain why they would not be)? (My first question, really looking forward to the responses.) The example below is obviously not the code in question but reflects the scenario:  Please excuse the code example, it looks fine in the editor preview?? for (int i =0; i&lt; 10; i++) {     decimal? testDecimal;     string testString;      switch( i % 2  )     {         case 0:         testDecimal = i / ( decimal ).32;         testString = i.ToString();             break;         default:             testDecimal = null;             testString = null;             break;     }      Console.WriteLine( &quot;Loop {0}: testDecimal={1} - testString={2}&quot;, i, testDecimal , testString ); }   EDIT: Sorry, had to rush out for child care issue. The issue was that the prod code had was that the switch statement was huge and in some &quot;case&quot;'s a check on a class' property was being made, like if (myObject.Prop != null) then testString = myObject.Stringval... At the end of the switch, (outside) a check on testString == null was being made but it was holding the value from the last iteration,hence not being null as the coder assumed with the variable being declared within the loop. Sorry if my question and example was a bit off, I got the phone call about the day care as I was banging it together. I should have mentioned I compared IL from both variables in and out the loop. So, is the common opinion that &quot;obviously the variables would not be reinitialized on each loop&quot;? A little more info, the variables WHERE being initialized on each iteration until someone got over enthusiastic with ReSharper pointing out &quot;the value is never used&quot; and removed them.  EDIT: Folks, I thank you all. As my first post I see how much clearer I should be in the future. The cause of our unexpected variable assignment can me placed on an inexperienced developer doing everything ReSharper told him and not running any unit tests after he ran a &quot;Code Cleanup&quot; on an entire solution. Looking at the history of this module in VSS I see variables Where declared outside of the loop and where initialized on each iteration. The person in question wanted his ReSharper to show &quot;all green&quot; so &quot;moved his variables closer to assignment&quot; then &quot;Removed redundant assignment&quot;! I don't think he will be doing it again...now to spend the weekend running all the unit tests he missed! How to do mark a question as answered?
100856
Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this:  &gt;&gt;&gt; class Foo: ...     bar = 'hello' ...     baz = 'world' ... &gt;&gt;&gt; f = Foo() &gt;&gt;&gt; props(f) { 'bar' : 'hello', 'baz' : 'world' }   NOTE: It should not include methods. Only fields.
32595
I need to set a constant value as true or false for the particular scenario not sure correct working or not const test = data.findIndex(d =&gt; d.Fname === '' &amp;&amp; d.Lname === '') &lt; 0 ? false : true;  if fname and Lname both are blank then i want to set test as false not sure what is happening here.
2961
I have a JavaScript object like the following:  var p = {     "p1": "value1",     "p2": "value2",     "p3": "value3" };   Now I want to loop through all p elements (p1, p2, p3...) And get their keys and values. How can I do that?  I can modify the JavaScript object if necessary. My ultimate goal is to loop through some key value pairs and if possible I want to avoid using eval.
101106
I am creating a Random Math Engine using the BGE and I am wondering how I can do mathematical operations between two properties. Example: "Property 1 + Property 2" and then it would output the answer in text when you hit "A". But I don't know how to add/subtract/multiply/divide properties together.
19222
I can do an eval("something()"); to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?  An example of what I am trying to do is: I have an integer variable (say i) and I have multiple properties by the names: "Property1", "Property2", "Property3", etc. Now, I want to perform some operations on the " Propertyi " property depending on the value of i.   This is really simple with Javascript. Is there any way to do this with C#?
68745
In short, this is an assignment question for a course I am taking - the exact wording is this:  "Given n Boolean variables, how many 'semantically' different Boolean functions can you construct?"  Now, I had a crack at this myself - and got pretty stuck. The question doesnt state how many boolean operators there are (and, or, xor, nand, nor, iff, implies, not) nor does it state whether brackets should be used, i.e. a ^ (b v c) is different from (a ^ b) v c.  So, my question for you is - is this question possible given the limited information available?   Is it going to be something like ${n^x}$ where x is the number of boolean operators.  Any direction here would be greatly appreciated.
46432
What is the difference between bool and Boolean types in C#?
74763
I am creating many boolean properties and want to be able to control the properties with a single worker function. The property name will be the logic driver. Is this possible? If so how? Or do I need to create a function for each property?  import bpy from bpy.props import BoolProperty  def worker_func(self, context):     r""" How to get the name of the envoked property"""     print (self.name) #??     """         if prop_a:             do stuff for prop_a         if prop_b:             do stuff for prop_b         if prop_c:             do stuff for prop_c      """  bpy.types.Scene.prop_a = BoolProperty( update = worker_func ) bpy.types.Scene.prop_b = BoolProperty( update = worker_func ) bpy.types.Scene.prop_c = BoolProperty( update = worker_func )  class HelloWorldPanel(bpy.types.Panel):     bl_label = "Hello"     bl_idname = "OBJECT_PT_hello"     bl_space_type = 'VIEW_3D'     bl_region_type = 'UI'      def draw(self, context):         layout = self.layout         layout.prop(context.scene, "prop_a", text="a")         layout.prop(context.scene, "prop_b", text="b")         layout.prop(context.scene, "prop_c", text="c")    def register():     bpy.utils.register_class(HelloWorldPanel)   def unregister():     bpy.utils.unregister_class(HelloWorldPanel)   if __name__ == "__main__":     register()   Thanks you very much. A.Kal
12281
I entered this statement in JSLint:  var number = new Number(3);   And received the following message:     Do not use Number as a constructor.   Why is that? The statement is creating a number object, not a primitive value, so I don't see why using new is a problem.  EDIT: Thanks for all the responses. They've got me thinking further, so I posted a follow-up question .
13706
The canonical way to return multiple values in languages that support it is often . Option: Using a tuple Consider this trivial example: def f(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return (y0, y1, y2)  However, this quickly gets problematic as the number of values returned increases. What if you want to return four or five values? Sure, you could keep tupling them, but it gets easy to forget which value is where. It's also rather ugly to unpack them wherever you want to receive them. Option: Using a dictionary The next logical step seems to be to introduce some sort of 'record notation'. In Python, the obvious way to do this is by means of a dict. Consider the following: def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return {'y0': y0, 'y1': y1 ,'y2': y2}  (Just to be clear, y0, y1, and y2 are just meant as abstract identifiers. As pointed out, in practice you'd use meaningful identifiers.) Now, we have a mechanism whereby we can project out a particular member of the returned object. For example, result['y0']  Option: Using a class However, there is another option. We could instead return a specialized structure. I've framed this in the context of Python, but I'm sure it applies to other languages as well. Indeed, if you were working in C this might very well be your only option. Here goes: class ReturnValue:   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  def g(x):   y0 = x + 1   y1 = x * 3   y2 = y0 ** y3   return ReturnValue(y0, y1, y2)  In Python the previous two are perhaps very similar in terms of plumbing - after all { y0, y1, y2 } just end up being entries in the internal __dict__ of the ReturnValue. There is one additional feature provided by Python though for tiny objects, the __slots__ attribute. The class could be expressed as: class ReturnValue(object):   __slots__ = [&quot;y0&quot;, &quot;y1&quot;, &quot;y2&quot;]   def __init__(self, y0, y1, y2):      self.y0 = y0      self.y1 = y1      self.y2 = y2  From the :  The __slots__ declaration takes a sequence of instance variables and reserves just enough space in each instance to hold a value for each variable. Space is saved because __dict__ is not created for each instance.  Option: Using a  (Python 3.7+) Using Python 3.7's new dataclasses, return a class with automatically added special methods, typing and other useful tools: @dataclass class Returnvalue:     y0: int     y1: float     y3: int  def total_cost(x):     y0 = x + 1     y1 = x * 3     y2 = y0 ** y3     return ReturnValue(y0, y1, y2)  Option: Using a list Another suggestion which I'd overlooked comes from Bill the Lizard: def h(x):   result = [x + 1]   result.append(x * 3)   result.append(y0 ** y3)   return result  This is my least favorite method though. I suppose I'm tainted by exposure to Haskell, but the idea of mixed-type lists has always felt uncomfortable to me. In this particular example the list is -not- mixed type, but it conceivably could be. A list used in this way really doesn't gain anything with respect to the tuple as far as I can tell. The only real difference between lists and tuples in Python is that lists are , whereas tuples are not. I personally tend to carry over the conventions from functional programming: use lists for any number of elements of the same type, and tuples for a fixed number of elements of predetermined types. Question After the lengthy preamble, comes the inevitable question. Which method (do you think) is best?