What he does is see if this property name exists in an empty object. So, for example, it will filter out toString (for implementations that are not errors regarding toString and in ; IE is).
It could be an attempt to get around people adding things to Object.prototype (this is a very, very bad idea). For instance:
Object.prototype.foo = "bar";
If I want to copy t , including its inherited property x from Thingy , but not including the foo property, which it inherits from Object , I could use this if (name in {}) to skip them.
Keep in mind that this is not a very smart way to do this, as it will not work if I do this:
var t = new Thingy(1, 2); t.foo = "charlie";
Now t has its own foo , which I supposedly would like to copy.
More thorough check:
dest = {}; blank = {}; // No need to recreate it on every iteration for (name in src) { if (src.hasOwnProperty(name) || !(name in blank)) { dest[name] = src[name]; } }
This will filter out only those that are inherited, or at least can be inherited, from Object . But even that is spoiled; What if it inherits the value for the property, but not the value from Object (for example, something in the middle - Thingy possible - overrides Object by default)?
So you might want to reorganize this code that you inherited, perhaps in terms of using hasOwnProperty and make sure that nothing in your application puts things in Object.prototype .