Checking if an object is empty in EcmaScript5 / Javascript
I was getting a JSON response from a server request that can contain just an empty value (this is, nothing, nothing de nothing that we Spaniards say). On checking if the object had anything within I did this which seemed to work... for a while: [sourcecode language="js" wraplines="false"] var d = response.data; var person = new Person(d); /**************/ // inside Person constructor: if (d) { this.Id = d.Id; this.Name = d.Name; ... } ... [/sourcecode] And that worked quite fine, as sometimes I want to instantiate a Person object without giving it any data, that's a null or "undefined" and checking if (d) exists just works. But what if d does exist but it's empty? Coming from the response I have "something", an empty something, it has no properties, no…