Hacker News new | past | comments | ask | show | jobs | submit login

Another way to call a function without parentheses is with an ES5 getter (or ES6 proxy):

    // The function we want to call
    function foo () { console.log('Hello!') }

    // ES5 getter:
    x = {}
    Object.defineProperty(x, 'foo', {get: foo})

    // Call it:
    x.foo               // Outputs 'Hello!'
What if we want to say "foo" instead of "x.foo"? Put a getter on window:

    Object.defineProperty(window, 'bar', {get: foo})

    // Call it:
    bar                 // Outputs "Hello!"
To pass arguments, use a setter instead:

    Object.defineProperty(window, 'hello', {set:
        function (x) {console.log('Hello '+x+'!')}

    // Call it:
    hello = 'michael'   // Outputs "Hello michael!'
To support multiple arguments, pass an array or hash.

    // Call it:
    hello = 'michael'   // Outputs "Hello michael!'
This makes me uncomfortable.

This should ideally trigger XHR back to the server (preferably async, with no error checking or retry) which then invokes a SELECT for nonexistant rows on a schema with a bunch of query triggers attached that store the queried-for data after first performing an HTTP request (from inside the DB, in a stored procedure) to translate the data to another language. (The translation service does not provide an API; the stored procedure extracts the response out of the HTML using a combination of 13 regular expressions and 2 substr() calls.) The original un-translated data should not be stored.

With great power comes great responsibility. This is a situation in which the old axiom, "don't write stupid code", comes into play.

But stupid code is the most fun.

You can also invoke the function by doing foo["bar"]: https://runkit.com/me1000/5ba283ad8bb2580012c875e8

You can also call a constructor passing no arguments without the parens. `var x = new Foo`

Although this is possible, most linters don’t allow it (with default settings on)

This is precisely why Kyle Simpson says there's no such thing as purity in JS

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact