Check if Deep Property Exists

JavaScript performance comparison

Test case created by netpoetica

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<!-- lodash contrib : no CDN :( -->
<script type='text/javascript'>
// lodash-contrib v241.4.14
// =========================

// > 
// > (c) 2013 Michael Fogus, DocumentCloud and Investigative Reporters & Editors
// > (c) 2013 Refael Ackermann & Empeeric
// > lodash-contrib may be freely distributed under the MIT license.

!function(a){function b(a){return e.isElement(a)?a.children:a}function c(a,b,c,d,i,j){var k=[];return function l(a,m,n){if(e.isObject(a)){if(k.indexOf(a)>=0)throw new TypeError(h);k.push(a)}if(c){var o=c.call(i,a,m,n);if(o===g)return g;if(o===f)return}var p,q=b(a);if(e.isObject(q)&&!e.isEmpty(q)){j&&(p=e.isArray(a)?[]:{});var r=e.any(q,function(b,c){var d=l(b,c,a);return d===g?!0:void(p&&(p[c]=d))});if(r)return g}return d?d.call(i,a,m,n,p):void 0}(a)}function d(a,b,c){var d=[];return this.preorder(a,function(a,g){return c||g!=b?void(e.has(a,b)&&(d[d.length]=a[b])):f}),d}var e=a._||require("lodash"),f={},g={},h="Not a tree: same object found in two different branches",i={find:function(a,b,c){var d;return this.preorder(a,function(a,e,f){return b.call(c,a,e,f)?(d=a,g):void 0},c),d},filter:function(a,b,c,d){var e=[];return null==a?e:(b(a,function(a,b,f){c.call(d,a,b,f)&&e.push(a)},null,this._traversalStrategy),e)},reject:function(a,b,c,d){return this.filter(a,b,function(a,b,e){return!c.call(d,a,b,e)})},map:function(a,b,c,d){var e=[];return b(a,function(a,b,f){e[e.length]=c.call(d,a,b,f)},null,this._traversalStrategy),e},pluck:function(a,b){return d.call(this,a,b,!1)},pluckRec:function(a,b){return d.call(this,a,b,!0)},postorder:function(a,b,d,e){e=e||this._traversalStrategy,c(a,e,null,b,d)},preorder:function(a,b,d,e){e=e||this._traversalStrategy,c(a,e,b,null,d)},reduce:function(a,b,d,e){var f=function(a,c,e,f){return b(f||d,a,c,e)};return c(a,this._traversalStrategy,null,f,e,!0)}};i.collect=i.map,i.detect=i.find,i.select=i.filter,e.walk=function(a){var c=e.clone(i);return e.bindAll.apply(null,[c].concat(e.keys(c))),c._traversalStrategy=a||b,c},e.extend(e.walk,e.walk())}(this),function(a){function b(a){return function(){if(1===arguments.length)return a.apply(this,arguments);throw new RangeError("Only a single argument may be accepted.")}}var c=a._||require("lodash"),d=function(){function a(c,d,e,f,g,h){return h===!0?f.unshift(g):f.push(g),f.length==e?c.apply(d,f):b(function(){return a(c,d,e,f.slice(0),arguments[0],h)})}return function(c,d){var e=this;return b(function(){return a(c,e,c.length,[],arguments[0],d)})}}(),e=function(){var a=[];return function(b){if("function"!=typeof b)throw new Error("Argument 1 must be a function.");var c=b.length;return void 0===a[c]&&(a[c]=function(a){return function(){if(arguments.length!==c)throw new RangeError(c+" arguments must be applied.");return a.apply(this,arguments)}}),a[c](b)}}(),f=function(a){return d.call(this,a,!0)},g=function(a){return b(function(c){return b(function(b){return a.call(this,b,c)})})},h=function(a){return b(function(c){return b(function(d){return b(function(b){return a.call(this,b,d,c)})})})};c.mixin({fix:function(a){var b=c.rest(arguments),d=function(){for(var d=b.slice(),e=0,f=0;f<(d.length||e<arguments.length);f++)d[f]===c&&(d[f]=arguments[e++]);return a.apply(null,d)};return d._original=a,d},unary:function(a){return function(b){return a.call(this,b)}},binary:function(a){return function(b,c){return a.call(this,b,c)}},ternary:function(a){return function(b,c,d){return a.call(this,b,c,d)}},quaternary:function(a){return function(b,c,d,e){return a.call(this,b,c,d,e)}},curry:d,curryRight:f,rCurry:f,curry2:function(a){return b(function(c){return b(function(b){return a.call(this,c,b)})})},curry3:function(a){return b(function(c){return b(function(d){return b(function(b){return a.call(this,c,d,b)})})})},curryRight2:g,rcurry2:g,curryRight3:h,rcurry3:h,enforce:e}),c.arity=function(){var a={};return function b(c,d){if(null==a[c]){for(var e=new Array(c),f=0;c>f;++f)e[f]="__"+f;var g=e.join(),h="return function ("+g+") { return fun.apply(this, arguments); };";a[c]=new Function(["fun"],h)}return null==d?function(a){return b(c,a)}:a[c](d)}}()}(this),function(a){function b(a,b){return c.arity(a.length,function(){return a.apply(this,h.call(arguments,b))})}var c=a._||require("lodash"),d=function(a){return null!=a},e=function(a){return a!==!1&&d(a)},f=[].reverse,g=[].slice,h=[].map,i=function(a){return function(b,c){return 1===arguments.length?function(c){return a(b,c)}:a(b,c)}};c.mixin({always:c.constant,pipeline:function(){var a=c.isArray(arguments[0])?arguments[0]:arguments;return function(b){return c.reduce(a,function(a,b){return b(a)},b)}},conjoin:function(){var a=arguments;return function(b){return c.every(b,function(b){return c.every(a,function(a){return a(b)})})}},disjoin:function(){var a=arguments;return function(b){return c.some(b,function(b){return c.some(a,function(a){return a(b)})})}},comparator:function(a){return function(b,c){return e(a(b,c))?-1:e(a(c,b))?1:0}},complement:function(a){return function(){return!a.apply(this,arguments)}},splat:function(a){return function(b){return a.apply(this,b)}},unsplat:function(a){var b=a.length;return 1>b?a:1===b?function(){return a.call(this,g.call(arguments,0))}:function(){var c=arguments.length,d=g.call(arguments,0,b-1),e=Math.max(b-c-1,0),f=new Array(e),h=g.call(arguments,a.length-1);return a.apply(this,d.concat(f).concat([h]))}},unsplatl:function(a){var b=a.length;return 1>b?a:1===b?function(){return a.call(this,g.call(arguments,0))}:function(){var c=arguments.length,d=g.call(arguments,Math.max(c-b+1,0)),e=g.call(arguments,0,Math.max(c-b+1,0));return a.apply(this,[e].concat(d))}},mapArgs:i(b),juxt:function(){var a=arguments;return function(){var b=arguments;return c.map(a,function(a){return a.apply(this,b)},this)}},fnull:function(a){var b=c.rest(arguments);return function(){for(var e=c.toArray(arguments),f=c.size(b),g=0;f>g;g++)d(e[g])||(e[g]=b[g]);return a.apply(this,e)}},flip2:function(a){return function(){var b=g.call(arguments);return b[0]=arguments[1],b[1]=arguments[0],a.apply(this,b)}},flip:function(a){return function(){var b=f.call(arguments);return a.apply(this,b)}},functionalize:function(a){return function(b){return a.apply(b,c.rest(arguments))}},methodize:function(a){return function(){return a.apply(null,c.cons(this,arguments))}},k:c.always,t:c.pipeline}),c.unsplatr=c.unsplat,c.mapArgsWith=i(c.flip(b)),c.bound=function(a,b){var d=a[b];if(!c.isFunction(d))throw new TypeError("Expected property to be a function");return c.bind(d,a)}}(this),function(a){var b=a._||require("lodash"),c=Array.prototype.slice;b.mixin({attempt:function(a,d){if(null==a)return void 0;var e=a[d],f=c.call(arguments,2);return b.isFunction(e)?e.apply(a,f):void 0}})}(this),function(a){function b(a){return function(b){return a.call(this,b)}}function c(a,b,c){var d,e;for(d=void 0!==c?c:a(),e=a();null!=e;)d=b.call(e,d,e),e=a();return d}function d(a,b){var c=x;return function(){return c===x?c=a:null!=c&&(c=b.call(c,c)),c}}function e(a,b){var c,d,e=a;return function(){return null!=e?(c=b.call(e,e),d=c[1],e=null!=d?c[0]:void 0,d):void 0}}function f(a,b,c){var d=c;return function(){var c=a();return null==c?c:d=void 0===d?c:b.call(c,d,c)}}function g(a,b,c){var d,e,f=c;return function(){return e=a(),null==e?e:void 0===f?f=e:(d=b.call(e,f,e),f=d[0],d[1])}}function h(a,b){return function(){var c;return c=a(),null!=c?b.call(c,c):void 0}}function i(a,b){var c=null;return function(){var d,e;if(null==c){if(e=a(),null==e)return void(c=null);c=b.call(e,e)}for(;null==d;)if(d=c(),null==d){if(e=a(),null==e)return void(c=null);c=b.call(e,e)}return d}}function j(a,b){return function(){var c;for(c=a();null!=c;){if(b.call(c,c))return c;c=a()}return void 0}}function l(a,b){return j(a,function(a){return!b(a)})}function m(a,b){return j(a,b)()}function n(a,b,c){for(var d=0;b-->0;)a();return null!=c?function(){return++d<=c?a():void 0}:a}function o(a,b){return n(a,null==b?1:b)}function p(a,b){return n(a,0,null==b?1:b)}function q(a){var b=0;return function(){return a[b++]}}function r(a){var b,c,d;return b=0,d=[],c=function(){var e,f;return e=a[b++],e instanceof Array?(d.push({array:a,index:b}),a=e,b=0,c()):void 0===e?d.length>0?(f=d.pop(),a=f.array,b=f.index,c()):void 0:e}}function s(a){return function(){return a}}function t(a,b,c){return function(){var d;return a>b?void 0:(d=a,a+=c,d)}}function u(a,b,c){return function(){var d;return b>a?void 0:(d=a,a-=c,d)}}function v(a,b,c){return null==a?t(1,1/0,1):null==b?t(a,1/0,1):null==c?b>=a?t(a,b,1):u(a,b,1):c>0?t(a,b,c):0>c?u(a,b,Math.abs(c)):k(a)}var w=a._||require("lodash"),x={},y=b(v);w.iterators={accumulate:f,accumulateWithReturn:g,foldl:c,reduce:c,unfold:d,unfoldWithReturn:e,map:h,mapcat:i,select:j,reject:l,filter:j,find:m,slice:n,drop:o,take:p,List:q,Tree:r,constant:s,K:s,numbers:y,range:v}}(this,void 0),function(a){var b=a._||require("lodash");b.mixin({isInstanceOf:function(a,b){return a instanceof b},isAssociative:function(a){return b.isArray(a)||b.isObject(a)||b.isArguments(a)},isIndexed:function(a){return b.isArray(a)||b.isString(a)||b.isArguments(a)},isSequential:function(a){return b.isArray(a)||b.isArguments(a)},isZero:function(a){return 0===a},isEven:function(a){return b.isFinite(a)&&0===(1&a)},isOdd:function(a){return b.isFinite(a)&&!b.isEven(a)},isPositive:function(a){return a>0},isNegative:function(a){return 0>a},isValidDate:function(a){return b.isDate(a)&&!b.isNaN(a.getTime())},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},isInteger:function(a){return b.isNumeric(a)&&a%1===0},isFloat:function(a){return b.isNumeric(a)&&!b.isInteger(a)},isJSON:function(a){try{JSON.parse(a)}catch(b){return!1}return!0},isIncreasing:function(){var a=b.size(arguments);if(1===a)return!0;if(2===a)return arguments[0]<arguments[1];for(var c=1;a>c;c++)if(arguments[c-1]>=arguments[c])return!1;return!0},isDecreasing:function(){var a=b.size(arguments);if(1===a)return!0;if(2===a)return arguments[0]>arguments[1];for(var c=1;a>c;c++)if(arguments[c-1]<=arguments[c])return!1;return!0}})}(this),function(a){var b=a._||require("lodash"),c=(Array.prototype.slice,Array.prototype.concat),d=function(a){return null!=a},e=function(a){return a!==!1&&d(a)},f=function(a){return b.isArray(a)||b.isObject(a)},g=function(a){return function(b){return function(c){return a(c,b)}}};b.mixin({merge:function(){var a=b.some(arguments)?{}:null;return e(a)&&b.extend.apply(null,c.call([a],b.toArray(arguments))),a},renameKeys:function(a,e){return b.reduce(e,function(b,c,e){return d(a[e])?(b[c]=a[e],b):b},b.omit.apply(null,c.call([a],b.keys(e))))},snapshot:function(a){if(null==a||"object"!=typeof a)return a;var c=new a.constructor;for(var d in a)a.hasOwnProperty(d)&&(c[d]=b.snapshot(a[d]));return c},updatePath:function(a,c,e,g){if(!f(a))throw new TypeError("Attempted to update a non-associative object.");if(!d(e))return c(a);var h=b.isArray(e),i=h?e:[e],j=h?b.snapshot(a):b.clone(a),k=b.last(i),l=j;return b.each(b.initial(i),function(a){g&&!b.has(l,a)&&(l[a]=b.clone(g)),l=l[a]}),l[k]=c(l[k]),j},setPath:function(a,c,e,f){if(!d(e))throw new TypeError("Attempted to set a property at a null path.");return b.updatePath(a,function(){return c},e,f)},frequencies:g(b.countBy)(b.identity)})}(this),function(a){{var b=a._||require("lodash"),c=Array.prototype.concat,d=Array.prototype;d.slice}b.mixin({accessor:function(a){return function(b){return b&&b[a]}},dictionary:function(a){return function(b){return a&&b&&a[b]}},selectKeys:function(a,d){return b.pick.apply(null,c.call([a],d))},kv:function(a,c){return b.has(a,c)?[c,a[c]]:void 0},getPath:function e(a,c){return"string"==typeof c&&(c=c.split(".")),void 0===a?void 0:0===c.length?a:null===a?void 0:e(a[b.first(c)],b.rest(c))},hasPath:function f(a,c){"string"==typeof c&&(c=c.split("."));var d=c.length;return null==a&&d>0?!1:c[0]in a?1===d?!0:f(a[b.first(c)],b.rest(c)):!1},pickWhen:function(a,c){var d={};return b.each(a,function(b,e){c(a[e])&&(d[e]=a[e])}),d},omitWhen:function(a,c){return b.pickWhen(a,function(a){return!c(a)})}})}(this),function(a){function b(a){return function(){return A.reduce(arguments,a)}}function c(a){return function(){for(var b,c=0;c<arguments.length-1;c++)if(b=a(arguments[c],arguments[c+1]),b===!1)return b;return b}}function d(a){return function(){return!a.apply(this,arguments)}}function e(a,b){return a+b}function f(a,b){return a-b}function g(a,b){return a*b}function h(a,b){return a/b}function i(a,b){return a%b}function j(a){return++a}function k(a){return--a}function l(a){return-a}function m(a,b){return a&b}function n(a,b){return a|b}function o(a,b){return a^b}function p(a,b){return a<<b}function q(a,b){return a>>b}function r(a,b){return a>>>b}function s(a){return~a}function t(a,b){return a==b}function u(a,b){return a===b}function v(a){return!a}function w(a,b){return a>b}function x(a,b){return b>a}function y(a,b){return a>=b}function z(a,b){return b>=a}var A=a._||require("lodash");A.mixin({add:b(e),sub:b(f),mul:b(g),div:b(h),mod:i,inc:j,dec:k,neg:l,eq:c(t),seq:c(u),neq:d(c(t)),sneq:d(c(u)),not:v,gt:c(w),lt:c(x),gte:c(y),lte:c(z),bitwiseAnd:b(m),bitwiseOr:b(n),bitwiseXor:b(o),bitwiseNot:s,bitwiseLeft:b(p),bitwiseRight:b(q),bitwiseZ:b(r)})}(this),function(a){var b=a._||require("lodash"),c=/\+/g,d=/(?:([^\[]+))|(?:\[(.*?)\])/g,e=function(a){return decodeURIComponent(a.replace(c,"%20"))},f=function(a,c,d){return b.isUndefined(d)&&(d=!0),b.isArray(c)?b.map(c,function(b,c){return f(d?c:a+"[]",b,!1)}).join("&"):b.isObject(c)?b.map(c,function(b,c){return f(d?c:a+"["+c+"]",b,!1)}).join("&"):encodeURIComponent(a)+"="+encodeURIComponent(c)};b.mixin({explode:function(a){return a.split("")},fromQuery:function(a){var c,f,g,h,i,j=a.split("&"),k={};return b.each(j,function(a){for(a=a.split("="),c=e(a[0]),g=c,i=k,d.lastIndex=0;null!==(f=d.exec(c));)b.isUndefined(f[1])?(h=f[2],i[g]=i[g]||(h?{}:[]),i=i[g]):h=f[1],g=h||b.size(i);i[g]=e(a[1])}),k},implode:function(a){return a.join("")},camelCase:function(a){return a.replace(/[-_\s](\w)/g,function(a){return a[1].toUpperCase()})},toDash:function(a){return a=a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()}),"-"==a.charAt(0)?a.substr(1):a},snakeCase:function(a){return a=a.replace(/([A-Z])/g,function(a){return"_"+a.toLowerCase()}),"_"==a.charAt(0)?a.substr(1):a},toQuery:function(a){return f("",a)},strContains:function(a,b){if("string"!=typeof a)throw new TypeError;return-1!=a.indexOf(b)},capitalize:function(a){return a.charAt(0).toUpperCase()+a.slice(1)},titleCase:function(a){return a.replace(/(\b.)/g,function(a){return a.toUpperCase()})},slugify:function(a){return a.replace(/ /g,"-").replace(/\./,"").toLowerCase()},regexEscape:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},humanize:function(a){return b.capitalize(a.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/\b([A-Z]+)([A-Z])([a-z])/,"$1 $2$3"))},stripTags:function(a){var b=a.replace(/<\/?[^<>]*>/gi,"");return b}})}(this),function(a){var b=a._||require("lodash");b.mixin({done:function(a){var c=b(a);return c.stopTrampoline=!0,c},trampoline:function(a){for(var c=a.apply(a,b.rest(arguments));b.isFunction(c)&&(c=c(),!(c instanceof b&&c.stopTrampoline)););return c.value()}})}(this),function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){b.exports=function(a){var b=Array.prototype.slice,c=Array.prototype.concat,d=Array.prototype.sort,e=function(a){return null!=a};a.mixin({cat:function(){return a.reduce(arguments,function(d,e){return a.isArguments(e)?c.call(d,b.call(e)):c.call(d,e)},[])},cons:function(b,c){return a.cat([b],c)},chunk:function(b,c,d){var e=function(b){if(null==b)return[];var f=a.take(b,c);return c===a.size(f)?a.cons(f,e(a.drop(b,c))):d?[a.take(a.cat(f,d),c)]:[]};return e(b)},chunkAll:function(b,c,d){d=null!=d?d:c;var e=function(b,c,d){return a.isEmpty(b)?[]:a.cons(a.take(b,c),e(a.drop(b,d),c,d))};return e(b,c,d)},mapcat:function(b,c){return a.cat.apply(null,a.map(b,c))},interpose:function(c,d){if(!a.isArray(c))throw new TypeError;var e=a.size(c);return 0===e?c:1===e?c:b.call(a.mapcat(c,function(b){return a.cons(b,[d])}),0,-1)},weave:function(){return a.some(arguments)?1==arguments.length?arguments[0]:a.filter(a.flatten(a.zip.apply(null,arguments),!0),function(a){return null!=a}):[]},interleave:a.weave,repeat:function(b,c){return a.times(b,function(){return c})},cycle:function(b,c){return a.flatten(a.times(b,function(){return c}),!0)},splitAt:function(b,c){return[a.take(b,c),a.drop(b,c)]},iterateUntil:function(a,b,c){for(var d=[],e=a(c);b(e);)d.push(e),e=a(e);return d},takeSkipping:function(b,c){var d=[],e=a.size(b);if(0>=c)return[];if(1===c)return b;for(var f=0;e>f;f+=c)d.push(b[f]);return d},reductions:function(b,c,d){var e=[],f=d;return a.each(b,function(a,d){f=c(f,b[d]),e.push(f)}),e},keepIndexed:function(b,c){return a.filter(a.map(a.range(a.size(b)),function(a){return c(a,b[a])}),e)},reverseOrder:function(a){if("string"==typeof a)throw new TypeError("Strings cannot be reversed by _.reverseOrder");return b.call(a).reverse()},collate:function(b,c,f){if(!a.isArray(b))throw new TypeError("expected an array as the first argument");if(!a.isArray(c))throw new TypeError("expected an array as the second argument");return d.call(b,function(b,d){a.isFunction(f)?(valA=f.call(b),valB=f.call(d)):e(f)?(valA=b[f],valB=d[f]):(valA=b,valB=d);var g=a.indexOf(c,valA),h=a.indexOf(c,valB);return-1===g?1:-1===h?-1:g-h})}})}},{}],2:[function(a,b){b.exports=function(a){function b(d,e){return null==d?void 0:g(e)?a(e).map(function(a){return d[a]}).valueOf():b(d,c.call(arguments,1))}var c=Array.prototype.slice,d=Array.prototype.concat,e=function(a){return null!=a},f=function(a){return a!==!1&&e(a)},g=function(b){return a.isArray(b)||a.isArguments(b)};a.mixin({second:function(a,b,d){return null==a?void 0:null==b||d?a[1]:c.call(a,1,b)},third:function(a,b,d){return null==a?void 0:null==b||d?a[2]:c.call(a,2,b)},nth:function(a,b,c){return null==b||c?void 0:a[b]},nths:b,valuesAt:b,binPick:function h(b,d){return null==b?void 0:g(d)?a.nths(b,a.range(d.length).filter(function(a){return d[a]})):h(b,c.call(arguments,1))},takeWhile:function(b,c){if(!g(b))throw new TypeError;for(var d=a.size(b),e=0;d>e&&f(c(b[e]));e++);return a.take(b,e)},dropWhile:function(b,c){if(!g(b))throw new TypeError;for(var d=a.size(b),e=0;d>e&&f(c(b[e]));e++);return a.drop(b,e)},splitWith:function(b,c){return[a.takeWhile(b,c),a.dropWhile(b,c)]},partitionBy:function(b,c){if(a.isEmpty(b)||!e(b))return[];var f=a.first(b),g=c(f),h=d.call([f],a.takeWhile(a.rest(b),function(b){return a.isEqual(g,c(b))}));return d.call([h],a.partitionBy(a.drop(b,a.size(h)),c))},best:function(b,c){return a.reduce(b,function(a,b){return c(a,b)?a:b})},keep:function(b,c){if(!g(b))throw new TypeError("expected an array as the first argument");return a.filter(a.map(b,function(a){return c(a)}),e)}})}},{}],3:[function(a,b){b.exports=function(a){a.mixin({exists:function(a){return null!=a},truthy:function(b){return b!==!1&&a.exists(b)},falsey:function(b){return!a.truthy(b)},not:function(a){return!a},existsAll:function(){return a.every(arguments,a.exists)},truthyAll:function(){return a.every(arguments,a.truthy)},falseyAll:function(){return a.every(arguments,a.falsey)},firstExisting:function(){for(var b=0;b<arguments.length;b++)if(a.exists(arguments[b]))return arguments[b]}})}},{}],4:[function(a,b){a("../common-js/_.array.builders.js")(_),a("../common-js/_.array.selectors.js")(_),a("../common-js/_.util.existential.js")(_),b.exports=_},{"../common-js/_.array.builders.js":1,"../common-js/_.array.selectors.js":2,"../common-js/_.util.existential.js":3}]},{},[4]);
</script>
      
<script>
Benchmark.prototype.setup = function() {
  function propDeepExists(target, propPath){
    try {
       var result = eval("target." + propPath);
    } catch(e){
      return false;
    }
    return result ? true : false;
  }
  
  function checkNestedFast(obj /*, level1, level2, ... levelN*/ ) {
    // code by http://stackoverflow.com/users/15055/claudiu
    for (var i = 1; i < arguments.length; i++) {
      if (!obj.hasOwnProperty(arguments[i])) {
        return false;
      }
      obj = obj[arguments[i]];
    }
    return true;
  }
  
  function deeptest(target, s){
      // slightly modified version, original by http://stackoverflow.com/users/80860/kennebec
      s= s.split('.')
      var obj= target[s.shift()];
      while(obj && s.length) obj= obj[s.shift()];
      return obj;
  }
  
  var test = {
    level1: {
      level2: {
        level3: 'level3'
      }
    }
  };

};
</script>

Preparation code output

<!-- lodash contrib : no CDN :( -->

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
propDeepExists
propDeepExists(test, "level1.level2.level3"); // true
propDeepExists(test, "level1.level2.foo"); // false
pending…
checkNestedFast
checkNestedFast(test, 'level1', 'level2', 'level3'); // true
checkNestedFast(test, 'level1', 'level2', 'foo'); // false
pending…
deeptest
deeptest(test, 'level1.level2.level3'); // true
deeptest(test, 'level1.level2.foo'); // false
pending…
_.getPath (recursion)
_.getPath(test, "level1.level2.level3"); // true
_.getPath(test, "level1.level2.foo"); // false
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments