> Le 3 mars 2016 à 18:04, Michał Wadas <[email protected]> a écrit :
>
> Are there any plans/proposals to specify user defined callable objects?
>
> It's possible to extend Function, but it requires to specify function code as
> string and prevents usage of local variables.
>
> Eg:
>
> ```
> class Foo {
> constructor() {
> this.i=0;
> }
> [Symbol.call]() {
> return class.instance.i++; // new meta property
> }
> }
> const f = new Foo;
> typeof f === 'function';
> f instanceof Function === false; // most use cases would be Function
> instances
> f() === 0;
> f() === 1;
> f.call(null); // TypeError: undefined is not a function
> ```
The following code should work (it did for me in Chrome):
```js
class Foo {
constructor() {
let obj = () => obj.i++;
Object.setPrototypeOf(obj, new.target.prototype);
obj.i = 0;
return obj;
}
}
```
—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss