This repository was archived by the owner on Apr 3, 2025. It is now read-only.
This repository was archived by the owner on Apr 3, 2025. It is now read-only.
Suggestion: operator() and operator new #52
Open
Description
An operator()
can make an object become a Callable
with a function signature without actually make it a function
.
And a similar operator new
is also suggest to make the object a constructor
.
like this:
const foo = {
value: 1,
bar: {
value: 2,
[Symbol.operatorSet]: Operators.create({
"()"(thisArg, callee, ...args) {
return thisArg.value + callee.value + args[0]
},
"new"(callee, ...args) {
return Object.create(callee)
}
})
}
}
foo.bar(3) // 6
new foo.bar() // { [[prototype]]: foo }
(It might be a bad idea to actually allow the same object to have different operator()
and operator new
, but, who knows.)
Metadata
Metadata
Assignees
Labels
No labels