[Javascript] Object Not Defined

Mike Dougherty mdougherty at pbp.com
Sat Nov 12 19:59:47 CST 2011


On Sat, Nov 12, 2011 at 10:51 AM, Terry Riegel
<riegel at clearimageonline.com> wrote:
> I think this problem would be nice to have some sort of generalized
> helper function. Perhaps...
>
> if( exist(a.b.c.d.e.f) )
>
> All the solutions I have seen seem to be long and error prone.

Do you find yourself writing the kind of code that expects arbitrary
parameters to deep-search a complex hierarchy without being sure the
property tree exists?

I doubt it's possible to write a smartlyHandleAnything(parameter)
function that does more than describe the parameter rather than
attempt to use it for anything.  If I'm proven wrong, how wise is it
to make assumptions about arbitrary objects?

Perhaps a solution would be to create a constructor function to
manufacture your complex objects, then in your  function/methods that
accept these objects you could check the passed object's .constructor
property and be reasonably sure the object is correct for the method.
(and throw an error for anything else passed incorrectly)

Of course that'll likely require rethinking your whole object creation
paradigm - ymmv  :)


http://skilldrick.co.uk/2011/09/understanding-typeof-instanceof-and-constructor-in-javascript/


More information about the Javascript mailing list