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.