Functions should be reassignable
bug
```js
function main() {
"use strict"
function foo() { foo = function () { return 0 }; return 1 }
print(foo())
print(foo())
}
main()
```
Throws:
```
Uncaught exception: TypeError: invalid assignment to const 'foo'
```
But it shouldn't throw, it should print this:
```
1
0
```
This is actually used in ecosystem helpers, e.g. in https://npmjs.com/package/assert:
```js
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
```
关闭于 2026-02-08 5 条评论