var Object = function() { this.foo = "foo"; } var object = new Object(); object.getFoo = function() { return this.foo; } console.log(object.getFoo()); // foo class Object { /** * @var \Closure[] */ private $methods = []; private $foo = 'foo'; public function __set(string $name, \Closure $method) { $this->methods[$name] = $method->bindTo($this, self::class); } public function __call(string $name, a