Does `{ next() { next() } }` have a recursive method?

Glen Huang curvedmark at gmail.com
Tue Dec 16 20:03:31 PST 2014


To rephrase the problem:

Assuming `next` was never defined.

```js
let a = { next() { next() } };
a.next();
```

The result of running this code is runtime error or infinite recursion?

I tried to find the answer in the spec, but the initialization and calling of a function object is a bit overwhelming for me.

The evaluation of FunctionExpression contains a step "Call the CreateImmutableBinding concrete method of envRec passing name as the argument.” together with "Call the InitializeBinding concrete method of envRec passing name and closure as the arguments. I" guess that’s the steps enable directly calling function name in the function body? 

And since DefineMethod doesn’t have such steps, is it correct to assume the above snippet should result in a runtime error?

Thanks.


More information about the es-discuss mailing list