function A(name) { this.name = name } A.prototype.getName = function () { console.log(this.name) } function B(model) { this.model = model } B.prototype.getModel = function () { console.log(this.model) } function create(type, param) { // instanceof 会判断后面的构造函数的原型是否存在当前这个对象的原型链里 if (this instanceof create) { return new this[type](param) } else { return new create(type, param) } } create.prototype = { A, B } var c = new create('A', '123') console.log(c); // A {name: '123'} var d = create("B", 666) console.log(d); // B { model: 666 }