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

后端 未结 6 2237
死守一世寂寞
死守一世寂寞 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:48

    Another way:

    var factory = function(clazz /*, arguments*/) {
        var args = [].slice.call(arguments, 1);
        return new function() { 
            clazz.apply(this, args)
        }
    }
    

提交回复
热议问题