ES5 创建构造函数的私有属性

index.js

function Foo() {
  const list = [];
  this.push = function (val) {
    list.push(val);
  };
  this.getList = function () {
    console.log(list);
  };
}

const foo1 = new Foo();
const foo2 = new Foo();
foo1.push(1); 
foo1.getList(); // [ 1 ]
foo2.getList(); // []
原文地址:https://www.cnblogs.com/aisowe/p/15245929.html