How to convert an “object” into a function in JavaScript?

前端 未结 8 504
Happy的楠姐
Happy的楠姐 2020-12-01 08:53

JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function. How do you do the

8条回答
  •  伪装坚强ぢ
    2020-12-01 09:43

    var A = function(foo) {                                                                                                      
      var B = function() {                                                                                                       
        return A.prototype.constructor.apply(B, arguments);
      };
      B.prototype = A.prototype;                                                                                                 
      return B;                                                                                                                  
    }; 
    

提交回复
热议问题