javascript - jquery if check long object -


i know dojo has feature, how jquery or other libraries?

$.ifobject(foo.bar.baz.qux[0])  if (foo && foo.bar && foo.bar.baz && foo.bar.baz.qux[0]) 

assuming arbitrary size of object nesting, i'm looking sugar function check whether or not object i'm looking defined, , not crash server along way.

in case want dive coffee script, has great feature in ? operator.

if foo?.bar?.baz?.qux?[0]   alert 'yay!' 

which compiles nasty, yet efficient, javascript

var _ref, _ref2, _ref3; if (typeof foo !== "undefined" && foo !== null ? (_ref = foo.bar) != null ? (_ref2 = _ref.baz) != null ? (_ref3 = _ref2.qux) != null ? _ref3[0] : void 0 : void 0 : void 0 : void 0) {   alert('yay!'); } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -