create your own new operator
2022年5月1日小于 1 分钟
new
operator
create your own Question
new
operator is used to create new instance objects.
Do you know exactly what new
does?
You are asked to implement myNew()
, which should return an object just as what new
does but without using new
.
Pay attention to the return type of constructor.
Code
/**
* @param {Function} constructor
* @param {any[]} args - argument passed to the constructor
* `myNew(constructor, ...args)` should return the same as `new constructor(...args)`
*/
const myNew = (constructor, ...args) => {
// your code here
}