Passing Argument to JavaScript Object Getter

Getters do not require explicit invocation with parentheses and cannot therefore accept arguments. Their invocation is implicit via standard property access syntax, e.g. URIController.href.

From getter documentation on MDN:

The get syntax binds an object property to a function…

  • It must have exactly zero parameters

______

If you need to accept arguments, use a function instead:

var URIController = {
    href: function (url) {
        return url.location.href;
    }
}

Or using ES6 object function shorthand syntax:

const URIController = {
    href (url) {
        return url.location.href;
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)