A
A
artch2014-09-11 12:47:27
JavaScript
artch, 2014-09-11 12:47:27

Is there somewhere a question mark syntax from CoffeeScript without CoffeeScript?

There is syntactic sugar in CoffeeScript like this:
item.getFoo?().fooParam?.bar
This will match a long confusing js expression with checks for getFoo == null and fooParam == null. Question: Is there a way to use similar syntax in vanilla js? Another js-to-js compiler, some magic library? We use traceur, but unfortunately it doesn't have it, since this thing is not included in ES6 (and we would like to). Maybe someone has seen traceur forks with something like this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-09-11
Protko @Fesor

ES6 has a Proxy that you can use to do this.
https://developer.mozilla.org/en/docs/Web/JavaScript...

var data = {},
      dataProxy = new Proxy(data, {
           get: function (target, name) {
                // do the magic here!
           }
      });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question