Is there a javascript equivalent of python’s __getattr__ method? [duplicate]

It’s now possible if your browser has support for the ES6 Proxy feature. You can check this in the ECMAScript 6 compatibility table.

If you have the proxy support, you would use it as follows:

let handler = {
  get(target, name) {
    return `Value for attribute ${name}`
  }
}

let x = new Proxy({}, handler);
console.log(x.lskdjoau); // produces message: "Value of attribute 'lskdjoau'"

Works in chrome, firefox, and node.js. Downsides: doesn’t work in IE – freakin IE. Soon.

Leave a Comment

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