📜  javascript 构造函数与工厂函数 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:27.599000             🧑  作者: Mango

代码示例1
function ConstructorFunction() {
   this.someProp1 = "1";
   this.someProp2 = "2";
}
ConstructorFunction.prototype.someMethod = function() { /* whatever */ };

function factoryFunction() {
   var obj = {
      someProp1 : "1",
      someProp2 : "2",
      someMethod: function() { /* whatever */ }
   };
   // other code to manipulate obj in some way here
   return obj;
}