function createNamedFunction(name, body) {
return new Function("body", "return function " + name + "() {\n" + " \"use strict\";" + " return body.apply(this, arguments);\n" + "};\n")(body);
};
var errorName = 'InternalError';
var errorClass = createNamedFunction(errorName, function (message) {
this.name = errorName;
this.message = message;
});
动态方法生成问题:
以上写法再小程序中会提示 TypeError: (intermediate value) is not a function
不可能让你调用这个构造函数的,这样不就能搞热更新了,微信早就给禁用了,包括Function.prototype.constructor