[removed] How to create a new instance of a class without using the new keyword?

后端 未结 6 2234
死守一世寂寞
死守一世寂寞 2020-12-25 13:22

I think the following code will make the question clear.

// My class
var Class = function() { console.log(\"Constructor\"); };
Class.prototype = { method: fu         


        
6条回答
  •  心在旅途
    2020-12-25 13:52

    Doesn't this work?

    function factory(class_, ...arg) {
        return new class_(...arg);
    }
    

    I don't understand why you can't use new.

提交回复
热议问题