flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Left Right <olegsivo...@gmail.com>
Subject Re: [CODE] Short cleanup
Date Fri, 24 Feb 2012 11:09:37 GMT
OMG!!! Seriously, you are writing SDK code and you don't know what's the
difference between using `in' operator and calling a method defined on
Object.prototype is?

First of all, they are testing for different things. `in' is testing for a
key in a collection, key may or may not be a property, for example, a key
in the Dictionary is not a property. Object.prototype.hasOwnProperty() is a
slow to resolve and slow to execute function that will resolve the property
(which involves verifying access permissions and whether the enumeration of
the property is allowed). It is on average 4 times slower then `in' if it
is used to do the same thing.

Further more, whilst `in' has several legitimate use cases (such as
verifying whether the collection contains the key),
Object.prototype.hasOwnProperty() is usually an indication that you are
doing something wrong. For example, you did not define an interface to
abstract different object types for similar access, or you created a blob
class, you don't want to import because of too many dependencies - modular
architecture failure.
Further more, it isn't safe to use this function in mission-critical code,
because someone can easily redefine it for __every__ object in the project,
since it's defined on the prototype, and by redefining it may intercept
some of your data you passed to this function.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message