Comments on: Using proxies to mimic existential-operator behaviour https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: Martin https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/#comment-2345 Wed, 11 Apr 2012 02:16:04 +0000 https://j11y.io/?p=1990#comment-2345 ”mixIn” describes that properties are being copied from one object to another, other possible names: “aggregate”, “combine”, “merge”.
var foo = existentially(document.getElementById(‘foo’));
if (foo) { // yes, we still need the initial null check
foo.//firstChild$style$display// = ‘none’;
// won’t throw an error, even if `firstChild` doesn’t exist
}

]]>
By: alejandrolechuga https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/#comment-2344 Wed, 04 Jan 2012 19:37:51 +0000 https://j11y.io/?p=1990#comment-2344 Cool ! stuff bookmarked

]]>
By: alejandrolechuga https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/#comment-2343 Wed, 04 Jan 2012 19:36:53 +0000 https://j11y.io/?p=1990#comment-2343 http://blog.ramonlechuga.com/2010/10/20/checking-object-structure/

]]>
By: Jamie https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/#comment-2342 Tue, 03 Jan 2012 16:19:53 +0000 https://j11y.io/?p=1990#comment-2342 I guess it comes to where you draw the line between the value of a language construct, versus just using a regular function. I have a function that parses a string to determine existence just like this (which I actually use most often to call functions based on a string which is passed from an external data source, as in a route), like:

var bob = route(“obj.foo.bar.bob”); // returns null if nonexistent

It’s not as syntactically beautiful as “bob = obj.foo.bar.bob” would be, but is that bad? It’s easy enough to understand; it expresses a different intent than a native evaluation anyway (since it’s parameter is indeterminate); and since javascript is interpreted at run-time anyway, there’s no downside in terms of syntax checking as there might be in a compiled language. Though since the whole point here is that we don’t know if the operand exists, syntax checking doesn’t make much sense anyway. In that way I kind of think it’s more correct to keep it as a string in your code.

]]>
By: Martijn Saly https://j11y.io/javascript/using-proxies-to-mimic-existential-operator-behaviour/#comment-2341 Mon, 02 Jan 2012 15:31:05 +0000 https://j11y.io/?p=1990#comment-2341 This piece of code:
var bob = obj?.foo?.bar?.bob
Could be written in javascript without any proxies or other workarounds, natively. It’s just a little bit more verbose, but it’s stil one line of code:
var bob = (((obj || {}).foo || {}).bar || {}).bob;
Cool huh 🙂

]]>